Hi,

I am using a QGridLayout to show some widgets which I create on the fly, then delete, create others, etc. This all works fine, but on Mac OS X I get a really awful flickering (despite using setUpdatesEnabled()) while it's all fine on Windows and Linux.

I have created a small Qt project which reproduces the problem (see below). I would really appreciate if someone could tell me whether I missed something obvious or whether it's a 'bug' on Mac OS X.

Cheers, Alan.

Test.pro:
Qt Code:
  1. QT += core gui
  2.  
  3. TARGET = Test
  4. TEMPLATE = app
  5.  
  6. SOURCES += main.cpp\
  7. mainwindow.cpp
  8.  
  9. HEADERS += mainwindow.h
To copy to clipboard, switch view to plain text mode 
main.cpp:
Qt Code:
  1. #include <QtGui/QApplication>
  2. #include "mainwindow.h"
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. MainWindow w;
  8. w.show();
  9.  
  10. return a.exec();
  11. }
To copy to clipboard, switch view to plain text mode 
mainwindow.cpp:
Qt Code:
  1. #include "mainwindow.h"
  2.  
  3. #include <QGridLayout>
  4. #include <QPushButton>
  5.  
  6. MainWindow::MainWindow(QWidget *parent) :
  7. QMainWindow(parent)
  8. {
  9. mWidget = new QWidget(this);
  10.  
  11. mLayout = new QGridLayout(mWidget);
  12.  
  13. mWidget->setLayout(mLayout);
  14.  
  15. populate();
  16.  
  17. setCentralWidget(mWidget);
  18.  
  19. this->resize(600, 300);
  20. }
  21.  
  22. void MainWindow::populate()
  23. {
  24. setUpdatesEnabled(false);
  25.  
  26. for (int i = 0, iMax = mLayout->count(); i < iMax; ++i) {
  27. QLayoutItem *item = mLayout->takeAt(0);
  28.  
  29. delete item->widget();
  30. delete item;
  31. }
  32.  
  33. for (int i = 0; i < 3; ++i)
  34. for (int j = 0; j < 3; ++j) {
  35. QPushButton *button = new QPushButton("Click me!", mWidget);
  36.  
  37. connect(button, SIGNAL(clicked()), this, SLOT(populate()));
  38.  
  39. mLayout->addWidget(button, i, j);
  40. }
  41.  
  42. setUpdatesEnabled(true);
  43. }
To copy to clipboard, switch view to plain text mode 
mainwindow.h:
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5.  
  6.  
  7. class MainWindow : public QMainWindow
  8. {
  9. Q_OBJECT
  10.  
  11. public:
  12. explicit MainWindow(QWidget *parent = 0);
  13.  
  14. private:
  15. QWidget *mWidget;
  16. QGridLayout *mLayout;
  17.  
  18. private Q_SLOTS:
  19. void populate();
  20. };
  21.  
  22. #endif
To copy to clipboard, switch view to plain text mode