Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there a way to check next events?
Forum Updated to NodeBB v4.3 + New Features

Is there a way to check next events?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 654 Views 3 Watching
  • 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.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by
    #1

    Hello,

    I would like to check which event will be after QEvent::FocusIn in my application.

    I am now in FocusIn function and I know that will be other events after that ( for example mousePressEvent ). How to check it?

    I think about:

    qDebug()<<eventsQueque.nextEvent();

    JonBJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      I dont think you can check that.

      Can i ask what you need it for ?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by
        #3

        @mrjj A few days ago I ask about: why QT doesn't see all clicks on the QPushButton ( if I click on them I show a popup window ).

        Please check this code:

        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H
        
        #include <QMainWindow>
        #include <QPushButton>
        
        QT_BEGIN_NAMESPACE
        namespace Ui { class MainWindow; }
        QT_END_NAMESPACE
        
        class MainWindow : public QMainWindow
        {
            Q_OBJECT
        
        public:
            MainWindow(QWidget *parent = nullptr);
            ~MainWindow();
        
        public slots:
            void clickedSlot();
        private:
            Ui::MainWindow *ui;
            QPushButton *button;
            QWidget *widget;
        };
        #endif // MAINWINDOW_H
        
        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QDebug>
        
        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
            button = new QPushButton(this);
            button->setGeometry(100,100,100,100);
            connect(button, SIGNAL(clicked()), this, SLOT(clickedSlot()));
            widget = new QWidget;
            widget->setWindowFlag(Qt::Popup);
            widget->setFixedSize(300,300);
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        
        void MainWindow::clickedSlot()
        {
            static int click=1;
            qDebug()<<click;
            if(click%2==1)
            {
                widget->show();
            }
            else
            {
                widget->hide();
            }
            click++;
        }
        
        

        This code above is very simple - I only add pushButton and widget. Now please click 2 times fast in a "button". In a qDebug() I get only "1". QWidget should be hide and it is hide. But this hide is because of popup. Now I would like click next time. Now widget should be visible ( this is the third click ), but it isn't ( because QT thinks that is my second clicked on button ).

        And that queue with events could be helpful for me ( this is only my try - if you know something better to achieve what I want ( the click%2==1 show, click%2==0 hide, but when QT see all clicks ) - please write :) )

        Pl45m4P 1 Reply Last reply
        0
        • T TomNow99

          Hello,

          I would like to check which event will be after QEvent::FocusIn in my application.

          I am now in FocusIn function and I know that will be other events after that ( for example mousePressEvent ). How to check it?

          I think about:

          qDebug()<<eventsQueque.nextEvent();

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @TomNow99 said in Is there a way to check next events?:

          I would like to check which event will be after QEvent::FocusIn in my application.

          Only if you can see into the future ;-)

          You do not have access to the Qt event queue. If you really wanted to do something like this, you'd have to not act on current event, wait till the next event arrived and act on it there. Doubtless with a timeout.

          1 Reply Last reply
          0
          • T TomNow99

            @mrjj A few days ago I ask about: why QT doesn't see all clicks on the QPushButton ( if I click on them I show a popup window ).

            Please check this code:

            #ifndef MAINWINDOW_H
            #define MAINWINDOW_H
            
            #include <QMainWindow>
            #include <QPushButton>
            
            QT_BEGIN_NAMESPACE
            namespace Ui { class MainWindow; }
            QT_END_NAMESPACE
            
            class MainWindow : public QMainWindow
            {
                Q_OBJECT
            
            public:
                MainWindow(QWidget *parent = nullptr);
                ~MainWindow();
            
            public slots:
                void clickedSlot();
            private:
                Ui::MainWindow *ui;
                QPushButton *button;
                QWidget *widget;
            };
            #endif // MAINWINDOW_H
            
            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include <QDebug>
            
            MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                , ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
                button = new QPushButton(this);
                button->setGeometry(100,100,100,100);
                connect(button, SIGNAL(clicked()), this, SLOT(clickedSlot()));
                widget = new QWidget;
                widget->setWindowFlag(Qt::Popup);
                widget->setFixedSize(300,300);
            }
            
            MainWindow::~MainWindow()
            {
                delete ui;
            }
            
            void MainWindow::clickedSlot()
            {
                static int click=1;
                qDebug()<<click;
                if(click%2==1)
                {
                    widget->show();
                }
                else
                {
                    widget->hide();
                }
                click++;
            }
            
            

            This code above is very simple - I only add pushButton and widget. Now please click 2 times fast in a "button". In a qDebug() I get only "1". QWidget should be hide and it is hide. But this hide is because of popup. Now I would like click next time. Now widget should be visible ( this is the third click ), but it isn't ( because QT thinks that is my second clicked on button ).

            And that queue with events could be helpful for me ( this is only my try - if you know something better to achieve what I want ( the click%2==1 show, click%2==0 hide, but when QT see all clicks ) - please write :) )

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #5

            @TomNow99 said in Is there a way to check next events?:

            void MainWindow::clickedSlot()
            {
            static int click=1;
            qDebug()<<click;
            if(click%2==1)
            {
            widget->show();
            }
            else
            {
            widget->hide();
            }
            click++;
            }

            Instead of counting consecutive clicks, you could check, whether your dialog is shown already or not...

            void MainWindow::clickedSlot()
            {
                if( !widget->isVisible() )
                {
                     widget->show();
                }
                else{
                    widget->hide();
                }
            }
            

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0
            • T Offline
              T Offline
              TomNow99
              wrote on last edited by TomNow99
              #6

              @Pl45m4 Of course I tried your solution a few days ago. Please look: when the widget has set flag Qt::Popup and when it is visible, when I clicked pushButton with your code I always get widget->show(). Why? Popup is before clicked() signal, so popup hide widget I go to clicked slot and widget is hide, so I show it. Next click the same. So my every click is widget->show().

              Pl45m4P 1 Reply Last reply
              0
              • T TomNow99

                @Pl45m4 Of course I tried your solution a few days ago. Please look: when the widget has set flag Qt::Popup and when it is visible, when I clicked pushButton with your code I always get widget->show(). Why? Popup is before clicked() signal, so popup hide widget I go to clicked slot and widget is hide, so I show it. Next click the same. So my every click is widget->show().

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #7

                @TomNow99 said in Is there a way to check next events?:

                when I clicked pushButton with your code I always get widget->show()

                Yeah, that's how popups are supposed to work.

                But why do you want to hide your popup widget especially with this button, when your popup widget will hide on any click anyway? Why do you need Qt::Popup?


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  TomNow99
                  wrote on last edited by TomNow99
                  #8

                  @Pl45m4 I try create something like comboBox. This comboBox has 2 parts: pushButton and widget. When I clicked on pushButton I would like to show or hide widget. User can click outside this button or click on it, so I have to get part "show" and "hide" in clicked slot.

                  mrjjM 1 Reply Last reply
                  0
                  • T TomNow99

                    @Pl45m4 I try create something like comboBox. This comboBox has 2 parts: pushButton and widget. When I clicked on pushButton I would like to show or hide widget. User can click outside this button or click on it, so I have to get part "show" and "hide" in clicked slot.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @TomNow99

                    Hi
                    You can still do this with event filters.
                    https://forum.qt.io/topic/117690/popup-and-pushbutton-how-to-solve-it/2

                    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