Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Screen Tearing QOpenGLWidget for 2D Images Drawn with QPainter
Qt 6.11 is out! See what's new in the release blog

Screen Tearing QOpenGLWidget for 2D Images Drawn with QPainter

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 649 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zates
    wrote on last edited by
    #1

    Hi,

    I am trying to develop a QT Widgets app, by which I need to rotate large 2D images in real time. When doing so, I see some flickering/tearing of the images when they are moving quickly across the screen.

    Currently, I am using a QOpenGLWidget and drawing all the resources in the paintEvent method, and using a timer to call update() to refresh the screen

    MyWidget::MyWidget(QWidget *parent) :
        QOpenGLWidget(parent),
        background(":/images/background.png"),
        img1(":/images/resource1.png"),
        img2(":/images/resource2.png")
    {
        QTimer *timer = new QTimer(this);
        connect(timer, SIGNAL(timeout()), this, SLOT(update()));
        timer->start(0);
    }
    void MyWidget::paintEvent(QPaintEvent *event)
    {
        if (m_frameCount  == 0) {
             m_time.start();
         }
         m_frameCount++;
         QPainter painter(this);
         painter.drawPixmap(0,0,background);
         painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true);
         painter.drawPixmap(QPoint(464.0, 20.0), img1);
         QTransform trans;
         trans.translate(960,546);
         trans.rotate(240.0 / 8.0 * m_framecount / 1000.0 % 8000);
         trans.translate(-960, -546);
         painter.setTransform(trans);
         painter.drawImage(QPoint(714,450), img2);
         painter.resetTransform();
         painter.end();
    }
    

    I am getting around 30 FPS, I suppose the artifacts are from the refresh rate, is there any way to enable VSync?

    I am only drawing many 2D images with a lot of rotations and translations in a from a fixed viewpoint with a fixed background, is there a more efficient way to display these items utilizing OpenGL that will mitigate the artifacts?

    Is there a way to cache the background to increase performance?

    Thanks for the help!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved