Hi, I'm new to QT programming and I'm stuck with an annoying issue.
I am working on an application that needs to display about 250 widgetsin a ScrollArea. I have a button that collapses most of these widgets (using hide()). Pushing the button again will show() the widgets again.
Re-showing the widgets after they have been hidden is however quite slow (too slow in my opinion). This slowness is bad, but what is worse is that when I show() the widgets again, you can see the widgets get added an resized.

I have run my app on an old notebook and I get the exact same behaviour.
I have tried using setUpdatesEnabled, but that didn't make it any better.
I thought that maybe the ScrollArea is slowing it down. Or the QVBoxLayout. But none of this was true.
I'm under the impression that when I start the app, it actually draws faster than when I do a show() after a hide().

I'm using QT 4.2.2 Open source version on Windows XP. I'm compiling with Visual C++ 2005 Studio Express.
I'm including source code that isolates the problem. It is not the complete app of course, but it shows what is going wrong. I'm creating 50 buttons that are hidden when you push the "Push Me" button. Maybe on another system you'd need to use 250 buttons to see clearly what is happending.

Thanks for any help,

p

PS. Actually I don't really want to use 250 widgets, but I don't have a choice as the QTreeWidget does not allow me to have a QTreeWidgetItem span multiple columns (something the Java version appears to allow?).


The header file scroll.h:

Qt Code:
  1. #ifndef SCROLL_H_
  2. #define SCROLL_H_
  3.  
  4. #include <QtGui>
  5.  
  6. class MyFrame: public QScrollArea
  7. {
  8. Q_OBJECT
  9. public:
  10. MyFrame(QWidget* parent=0);
  11. public slots:
  12. void change(bool dummy);
  13. private:
  14. enum {number=50};
  15. QPushButton* pbs[number];
  16. QFrame *frame;
  17. QFrame *labelframe;
  18. QVBoxLayout *labellay;
  19. bool seeMe;
  20. };
  21.  
  22. #endif
To copy to clipboard, switch view to plain text mode 

The main code "scroll.cpp":

Qt Code:
  1. #include <QtGui>
  2. #include "scroll.h"
  3.  
  4. MyFrame::MyFrame(QWidget* parent): QScrollArea(parent), seeMe(1)
  5. {
  6. setWidgetResizable(true);
  7.  
  8. frame=new QFrame;
  9. frame->setFrameShape(QFrame::Box);
  10.  
  11. QPushButton *push=new QPushButton(tr("Push me"));
  12. connect(push, SIGNAL(clicked(bool)), this, SLOT(change(bool)));
  13. labelframe=new QFrame;
  14.  
  15. lay=new QVBoxLayout;
  16. lay->addWidget(push);
  17. lay->addWidget(labelframe);
  18. lay->addStretch(1);
  19. frame->setLayout(lay);
  20.  
  21. labellay=new QVBoxLayout;
  22. for (int i=0; i<number; i++) {
  23. pbs[i]=new QPushButton(tr("Button %1").arg(i));
  24. labellay->addWidget(pbs[i]);
  25. }
  26. labellay->addStretch(1);
  27. labelframe->setLayout(labellay);
  28.  
  29. setWidget(frame);
  30. }
  31.  
  32. void MyFrame::change(bool dummy)
  33. {
  34. seeMe=!seeMe;
  35. // labelframe->setUpdatesEnabled(false); // doesn't help much
  36. labelframe->setVisible(seeMe);
  37. // labelframe->setUpdatesEnabled(true);
  38. }
  39.  
  40. int main(int argc, char **argv)
  41. {
  42. QApplication app(argc, argv);
  43. MyFrame mf;
  44. mf.show();
  45. return app.exec();
  46. }
To copy to clipboard, switch view to plain text mode