agarny
6th July 2012, 17:15
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 += core gui
TARGET = Test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
main.cpp:
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp:
#include "mainwindow.h"
#include <QGridLayout>
#include <QPushButton>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
mWidget = new QWidget(this);
mLayout = new QGridLayout(mWidget);
mWidget->setLayout(mLayout);
populate();
setCentralWidget(mWidget);
this->resize(600, 300);
}
void MainWindow::populate()
{
setUpdatesEnabled(false);
for (int i = 0, iMax = mLayout->count(); i < iMax; ++i) {
QLayoutItem *item = mLayout->takeAt(0);
delete item->widget();
delete item;
}
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j) {
QPushButton *button = new QPushButton("Click me!", mWidget);
connect(button, SIGNAL(clicked()), this, SLOT(populate()));
mLayout->addWidget(button, i, j);
}
setUpdatesEnabled(true);
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QGridLayout;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
private:
QWidget *mWidget;
QGridLayout *mLayout;
private Q_SLOTS:
void populate();
};
#endif
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 += core gui
TARGET = Test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
main.cpp:
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp:
#include "mainwindow.h"
#include <QGridLayout>
#include <QPushButton>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
mWidget = new QWidget(this);
mLayout = new QGridLayout(mWidget);
mWidget->setLayout(mLayout);
populate();
setCentralWidget(mWidget);
this->resize(600, 300);
}
void MainWindow::populate()
{
setUpdatesEnabled(false);
for (int i = 0, iMax = mLayout->count(); i < iMax; ++i) {
QLayoutItem *item = mLayout->takeAt(0);
delete item->widget();
delete item;
}
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j) {
QPushButton *button = new QPushButton("Click me!", mWidget);
connect(button, SIGNAL(clicked()), this, SLOT(populate()));
mLayout->addWidget(button, i, j);
}
setUpdatesEnabled(true);
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QGridLayout;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
private:
QWidget *mWidget;
QGridLayout *mLayout;
private Q_SLOTS:
void populate();
};
#endif