1

I have a widget, and I add 300 pixmaps inside.

MyWidget::MyWidget( QWidget *parent )
{
    setParent(parent);
    FlowLayout *flowLayout = new FlowLayout(this, 2,2,2);
    setLayout(flowLayout);

    QPixmap* cupcakes = new QPixmap("Resources/Icons/pimpCupcakes.png");
    TilePixmap* tilePximap = new TilePixmap(cupcakes, 0);
    m_buttonGroup = new QButtonGroup(this);

    int id = 0;
    for(int i=0; i<300; ++i)
    {
        TilesetButton* buttonTmp = new TilesetButton(this, tilePximap);
        m_buttonGroup->addButton(buttonTmp, id);
        flowLayout->addWidget(buttonTmp);
        id++;
    }
}

I had this widget in a QTabWidget like this :

ui.tabWidget->addTab(myWidget, name);

I do this operation with another widget

ui.tabWidget->addTab(myWidget2, name);

in qt4.8, creation (and first draw) need approximatively 4 secondes and after that, switch between tab 1 and 2 is instantaneous.

in qt5, creation (and first draw) need approximatively 4 secondes (so like qt4.8) but after that, switch tab took always 4 secondes between the time when I clicked on the tab and when the signal "currentChanged(int)" emmited.

Qt5 need add some cache configs compared with qt4 ?

(project are identic, just the Qt version is different)

Edit : I do the same test not with pixmap but only with QPushButton* and a simple text on it. and it's the same problems. 3/4 sec latency between my clic and the tab switch.

I look if tabWidget code changed since qt4.8 but I saw nothing which could be the reason of this.

Mathieu T
  • 117
  • 2
  • 9
  • Perhaps you need to change your drawing algorithm? You need to make sure to not do too many operations on the UI thread at once as it will cause the UI to slow down. – Cameron Tinker Jun 24 '13 at 12:36
  • maybe but, what's new on qt5, because, it's the same algorithm in qt4.8 == instant switch (redraw) and qt5 == 4secondes to switch (redraw) with the same code/images/etc – Mathieu T Jun 25 '13 at 14:48

1 Answers1

2

You can significantly improve your performance by switching to a QGLWidget. Different "paint devices" in Qt have different performance, as seen in this question, the fastest possible solution is to use a QGLWidget with a QGLFramebufferObject.

Also, I think setParent(parent) is not needed, QObject takes care of that and QWidget inherits QObject.

Also, unrelated, but still, the correct term would be "slower" not "more slow".

Good luck!

Community
  • 1
  • 1
dtech
  • 47,916
  • 17
  • 112
  • 190
  • In my widget, I'm using QPushButton (MyPushButton) with a specific treatment and graphics (I used a css files for design) how use QButton (they have all one QPixmap on it) in a QGlWidget ? – Mathieu T Jun 25 '13 at 14:44
  • I agree with the QGLWidget approach. This will significantly improve drawing performance and application responsiveness. – Cameron Tinker Jun 25 '13 at 14:59
  • @MathieuT - just use `QGLWidget` instead of a regular widget and everything you put in it will automatically draw using OpenGL. Your push button will work the same way, QPainter has both a software (what you are using right now) and hardware (OpenGL) implementations. – dtech Jun 25 '13 at 16:53
  • Ok thanks ! It works, I have just a black color under my background color. I need to fix it. Thanks guy ! – Mathieu T Jun 26 '13 at 09:01