Reputation: 127
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.
Upvotes: 1
Views: 1202
Reputation: 49289
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!
Upvotes: 2