From f0c19d00e793573c08d3356e1e1043782103ef19 Mon Sep 17 00:00:00 2001 From: Gavin Liu Date: Tue, 23 Feb 2021 20:53:59 +0800 Subject: [PATCH] use QLabel instead of QPainter to draw framebuffer in Hello3D QT demo, for fixing screen flickering --- Hello3D/BuildQt/mainwindow.cpp | 8 ++++++-- Hello3D/BuildQt/mainwindow.h | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Hello3D/BuildQt/mainwindow.cpp b/Hello3D/BuildQt/mainwindow.cpp index 00b3cee..8d438b9 100644 --- a/Hello3D/BuildQt/mainwindow.cpp +++ b/Hello3D/BuildQt/mainwindow.cpp @@ -48,6 +48,11 @@ void MainWindow::init() QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(update())); timer->start(30);//30ms + + label = new QLabel; + label->setParent(this); + label->setFixedWidth(UI_WIDTH); + label->setFixedHeight(UI_HEIGHT); } void MainWindow::paintEvent(QPaintEvent* p) @@ -56,9 +61,8 @@ void MainWindow::paintEvent(QPaintEvent* p) static bool force_update = true; void* fb = getUiOfHello3D(NULL, NULL, force_update); if(fb){ - QPainter painter(this); QImage img((uchar*)fb, UI_WIDTH, UI_HEIGHT, QImage::Format_RGB16); - painter.drawImage(0, 0, img); + label->setPixmap(QPixmap::fromImage(img)); force_update = false; } } diff --git a/Hello3D/BuildQt/mainwindow.h b/Hello3D/BuildQt/mainwindow.h index b8b2714..2330023 100644 --- a/Hello3D/BuildQt/mainwindow.h +++ b/Hello3D/BuildQt/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include namespace Ui { class MainWindow; @@ -23,6 +24,8 @@ public: private: bool m_is_pressed; Ui::MainWindow *ui; + + QLabel *label; }; #endif // MAINWINDOW_H -- Gitee