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%.
The shape of the aircraft doesn't particularly matter, so any polygon would work for example purposes.
void Compass::paintEvent(QPaintEvent *pEvent)
painter.setWindow(-50, -50, 100, 100);
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
//Draw compass background
painter.drawEllipse(-48, -48, 96, 96);
//Pulled from the DrawAircraft function
QColor clrAircraft(0xEE, 0xEE, 0xEE);
QPen penAircraft(clrAircraft, 1);
painter.setWindow(-60, -60, 120, 120);
if (m_bolHasSensor && m_bolIsSensorFixed)
painter.rotate(m_dblPlatformHeading - m_dblSensorHeading);
painter.drawLine(0, -32, 0, -42);
//End DrawAircraft function
//Draw outer rim
painter.setPen (QPen (Qt::black, 2));
painter.drawEllipse(-41, -41, 82, 82);
Is there something obviously wrong here?
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.
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.