Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    [SOLVED] Awful flickering with QGridLayout on Mac OS X

    General and Desktop
    1
    2
    1992
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      agarny last edited by

      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&#40;&#41;;
      

      }@

      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@

      1 Reply Last reply Reply Quote 0
      • A
        agarny last edited by

        See http://www.qtcentre.org/threads/49840-Awful-flickering-with-QGridLayout-on-Mac-OS-X?p=223935#post223935 for the 'solution'...

        1 Reply Last reply Reply Quote 0
        • First post
          Last post