Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Why does QWidget always require update screen twice from hidden to showing.

Why does QWidget always require update screen twice from hidden to showing.

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 2 Posters 1.4k Views
  • 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.
  • E Offline
    E Offline
    ephone
    wrote on last edited by
    #1

    Hi All:
    I tried to program a test code as following, and run it.
    After application running, I press alt+tab to swap the QT application window.
    I see the w(MainWindow ) always receive 2 QEvent::Paint evnets.
    I have no idea for that symptom, does any one know what happen is it?
    Does the symptom impact QT GUI display performance.
    Thanks for viewing.

    class evtFilter:public QWidget
    {
    public:
    bool eventFilter(QObject * obj_p, QEvent * e_p)
    {

       // qDebug() << obj_p;
        if(e_p->type() == 12)
        {
            qDebug() << e_p->type();
        }
        return false;
    }
    

    };

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    evtFilter filter;
    w.installEventFilter(&filter);
    w.setGeometry(0, 0, 200, 200);
    w.show();

    return a.exec();
    

    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is MainWindow ? What does it contain ?

      Your filter is seeing two events however you don't check who got the events. That's what the first argument is for. Identify who go it.

      You should also state which OS you are running as well as Qt version.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ephone
        wrote on last edited by
        #3

        Hi SGait:
        Thanks for your response :).

        MainWindow is created by QT creator, it just inherit QWidget and the detail define as below.

        Due to MainWindow::paintEvent(QPaintEvent *p) is invoked twice when window swapping.
        so I install a event filter in MainWindow to double check the event forwarding.
        And it is 2 paint events when window swapping really.

        And the running environment as following
        OS: Windows 7
        Toolchain : MinGw 4.9.32
        QT version: 4.7.3

        namespace Ui {
        class MainWindow;
        }

        class MainWindow : public QMainWindow
        {
        Q_OBJECT

        public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();

        private:
        Ui::MainWindow *ui;
        void paintEvent(QPaintEvent *p);
        };

        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);
        }

        MainWindow::~MainWindow()
        {
        delete ui;
        }

        void MainWindow::paintEvent(QPaintEvent *p)
        {
        qDebug() << "11111111111";
        }

        class evtFilter:public QWidget
        {
        public:
        bool eventFilter(QObject * obj_p, QEvent * e_p)
        {

        // qDebug() << obj_p;
        if(e_p->type() == 12)
        {
        qDebug() << e_p->type();
        }
        return false;
        }
        };

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);
        MainWindow w;
        evtFilter filter;
        w.installEventFilter(&filter);
        w.setGeometry(0, 0, 200, 200);
        w.show();

        return a.exec();
        }

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Qt 4.7.3 ? Why that old outdated version ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ephone
            wrote on last edited by
            #5

            Hi SGaist:
            Because, I am developing QT application under old SoC,
            It is using original architecture(on QT 4.7.3).
            :)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              In that case, please consider updating to 4.8.7.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved