Thread: QT GUI is very slow.

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    163

    QT GUI is very slow.

    Hey all. Been a while since I've posted here, but I'm a bit stumped and I couldn't find any real good QT forums that are actually active.

    I've inherited some QT code which creates widgets for displaying various aircraft cockpit instruments. Unfortunately, it's a bit of a processor hog. I need to get this to not take up so much CPU, as there's potential for 40+ instances of this dialog to be active at a time(crazy, but that's part of the requirements). The following is a piece of the compass widget. I've pulled out enough so that it's still very slow(in my opinion) for what it's actually doing, and somebody with a decent amount of QT experience might see something obviously bad here.

    This is my paintEvent for the widget in question. It only gets updated every 400ms, yet is using between 6% and 10% of my CPU power(as seen in Task Manager, so that number may be off a bit). This is just one part of the compass, and the compass is one of about 15 widgets that I have to display. That means when everything is up and running my CPU is pretty much always above 50%.

    Code:
    void Compass::paintEvent(QPaintEvent *pEvent) 
    {	
        QPainter painter(this);
    
        painter.setViewport(pEvent->rect());
        painter.setWindow(-50, -50, 100, 100);
        painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
    
        //Draw compass background
        painter.setPen  (PEN_DARK_GREY0);
        painter.setBrush(COLOR_DARK_GREY );
        painter.drawEllipse(-48, -48, 96, 96);
        
        //Pulled from the DrawAircraft function
        QColor clrAircraft(0xEE, 0xEE, 0xEE);
        QPen penAircraft(clrAircraft, 1);
    
        painter.save();
        painter.setPen(penAircraft);
        painter.setWindow(-60, -60, 120, 120);
    
        if (m_bolHasSensor && m_bolIsSensorFixed)
            painter.rotate(m_dblPlatformHeading - m_dblSensorHeading);
    
        painter.drawConvexPolygon(&AIRCRAFT[0], 16);
        painter.drawLine(0, -32, 0, -42);
        painter.restore();
        //End DrawAircraft function
    
        //Draw outer rim
        painter.setPen  (QPen  (Qt::black, 2));
        painter.setBrush(QBrush(Qt::NoBrush));
        painter.drawEllipse(-41, -41, 82, 82);
    }
    The shape of the aircraft doesn't particularly matter, so any polygon would work for example purposes.

    Is there something obviously wrong here?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    A couple of thoughts.

    > painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
    Antialiasing makes the display look a lot better, but it does take a lot longer (compared to simply writing pixels) to perform.

    If it were being done on the GPU, it shouldn't be a problem. But old hardware (you did say inherited), and/or a mis-configured library not taking advantage of your hardware, could mean that all this detailed pixel work is happening on the main CPU.


    > painter.save();
    How much work does a save/restore do?
    In this example, it would seem the only thing you need to do "manually" is reset the window and rotation.

    But if the two components don't overlap, then doing "Draw outer rim" before DrawAircraft would avoid having to do any save/restore at all.

    If the static components of your widgets are intricate (lots of tick marks on circular dials for example), then perhaps consider rendering those to static bitmaps, then doing a single "blit" for the whole static image, then draw only the variable components.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. any shareware GUI to use for Windows ?
    By Amy N. in forum C Programming
    Replies: 6
    Last Post: 07-22-2009, 01:31 PM
  2. Qt 4 for a GUI?
    By Dino in forum Tech Board
    Replies: 6
    Last Post: 02-25-2008, 01:57 AM
  3. Gui: Qt vs. GTK vs. ?
    By pixsta in forum C++ Programming
    Replies: 3
    Last Post: 11-15-2005, 05:02 PM
  4. QT 3 GUI Programming
    By WebmasterMattD in forum Linux Programming
    Replies: 0
    Last Post: 01-02-2003, 04:14 AM
  5. EASY GUI development.. like with Qt?
    By rezonax in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2001, 01:18 PM