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. popup modal dialog does not have focus on touch screen

popup modal dialog does not have focus on touch screen

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 7 Posters 3.0k 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.
  • JoeCFDJ Online
    JoeCFDJ Online
    JoeCFD
    wrote on last edited by
    #1

    A modal dialog from a main window does not have focus and this causes that a button on the dialog has to be pressed twice for response. However, it does work with mouse click. Finger touch has to be done twice.

    MyDialog::MyDialog(QWidget *parent)
    :QDialog( parent )
    {
    ui.setupUi();
    setModal( true );
    setWindowFlags((Qt::WindowFlags)(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint));
    raise();
    activateWindow();
    setFocusPolicy( Qt::StrongFocus );
    setWindowModality( Qt::WindowModal );

    setFocus();
    

    }

    parent is the main widget on the main window and not null_ptr. Nothing helps.
    auto widget = QApplication::focusWidget();
    widget is something else, but my dialog.
    my dialog is launched with exec().

    What is wrong?

    JonBJ 1 Reply Last reply
    0
    • JoeCFDJ JoeCFD

      A modal dialog from a main window does not have focus and this causes that a button on the dialog has to be pressed twice for response. However, it does work with mouse click. Finger touch has to be done twice.

      MyDialog::MyDialog(QWidget *parent)
      :QDialog( parent )
      {
      ui.setupUi();
      setModal( true );
      setWindowFlags((Qt::WindowFlags)(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint));
      raise();
      activateWindow();
      setFocusPolicy( Qt::StrongFocus );
      setWindowModality( Qt::WindowModal );

      setFocus();
      

      }

      parent is the main widget on the main window and not null_ptr. Nothing helps.
      auto widget = QApplication::focusWidget();
      widget is something else, but my dialog.
      my dialog is launched with exec().

      What is wrong?

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

      @JoeCFD
      I may be quite wrong on this, but I thought/assumed stuff about raise/activate/focus, assuming you need them for the behaviour you want, would not have any effect until a window/dialog is show()n, and therefore does not belong in the constructor: rather should be in something like the QDialog::showEvent()?

      1 Reply Last reply
      1
      • JoeCFDJ Online
        JoeCFDJ Online
        JoeCFD
        wrote on last edited by
        #3

        Still not figured out. Any help?

        jsulmJ 1 Reply Last reply
        0
        • Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          So you have to click once inside your non-focused dialog with your mouse (focus + button click at once) but twice (first tap focus, second tap to press button) with a finger on your touchscreen?

          A tap on screen will trigger QTouchEvents and not QMouseEvents directly. There could be something wrong...

          Have you tried to debug / print the QEvent, which you get from one single tap on your dialog?


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

          ~E. W. Dijkstra

          JoeCFDJ Pl45m4P 3 Replies Last reply
          1
          • Pl45m4P Pl45m4

            So you have to click once inside your non-focused dialog with your mouse (focus + button click at once) but twice (first tap focus, second tap to press button) with a finger on your touchscreen?

            A tap on screen will trigger QTouchEvents and not QMouseEvents directly. There could be something wrong...

            Have you tried to debug / print the QEvent, which you get from one single tap on your dialog?

            JoeCFDJ Online
            JoeCFDJ Online
            JoeCFD
            wrote on last edited by
            #5

            @Pl45m4 Thanks for your reply. Right, I have to click mouse once(focus+button click at once), twice with finger on the touch screen. I will check the QTouchEvents out.

            1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              Still not figured out. Any help?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @JoeCFD Did you read what @JonB wrote?
              Calling raise/activate/focus in constructor isn't a good idea.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              JoeCFDJ 1 Reply Last reply
              2
              • jsulmJ jsulm

                @JoeCFD Did you read what @JonB wrote?
                Calling raise/activate/focus in constructor isn't a good idea.

                JoeCFDJ Online
                JoeCFDJ Online
                JoeCFD
                wrote on last edited by JoeCFD
                #7

                @jsulm I did. I moved them out. They were not there before. I still think it is a focus problem since all buttons work fine when pressed on the main window.

                1 Reply Last reply
                0
                • Pl45m4P Pl45m4

                  So you have to click once inside your non-focused dialog with your mouse (focus + button click at once) but twice (first tap focus, second tap to press button) with a finger on your touchscreen?

                  A tap on screen will trigger QTouchEvents and not QMouseEvents directly. There could be something wrong...

                  Have you tried to debug / print the QEvent, which you get from one single tap on your dialog?

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

                  @Pl45m4 said in popup modal dialog does not have focus on touch screen:

                  A tap on screen will trigger QTouchEvents and not QMouseEvents directly. There could be something wrong...

                  Have you checked the result of the QTouchEvent?
                  If Raise , Focus and so on are connected to the QMouseEvent and not to the QTouchEvent directly, maybe you have to emit or trigger some signals / events to have the same effect on finger tap as on mouse click.


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

                  ~E. W. Dijkstra

                  JoeCFDJ 1 Reply Last reply
                  0
                  • Pl45m4P Pl45m4

                    @Pl45m4 said in popup modal dialog does not have focus on touch screen:

                    A tap on screen will trigger QTouchEvents and not QMouseEvents directly. There could be something wrong...

                    Have you checked the result of the QTouchEvent?
                    If Raise , Focus and so on are connected to the QMouseEvent and not to the QTouchEvent directly, maybe you have to emit or trigger some signals / events to have the same effect on finger tap as on mouse click.

                    JoeCFDJ Online
                    JoeCFDJ Online
                    JoeCFD
                    wrote on last edited by
                    #9

                    In order to receive QTouchEvent, the button widget has to have attribute Qt::WA_AcceptTouchEvents. It is set and QTouchEvent can be received. Event filter is added to the buttons and dialog for QTouchEvent. Now one press on the touch screen activates one button. It works now. Thanks a lot for your tip.
                    However, the touch event can be received only for the dialog, but the buttons when the exact code is used to pop up the dialog from another main window.
                    I still think the focus is the root cause. The pop-up dialog simply can not get the focus.

                    1 Reply Last reply
                    0
                    • Pl45m4P Pl45m4

                      So you have to click once inside your non-focused dialog with your mouse (focus + button click at once) but twice (first tap focus, second tap to press button) with a finger on your touchscreen?

                      A tap on screen will trigger QTouchEvents and not QMouseEvents directly. There could be something wrong...

                      Have you tried to debug / print the QEvent, which you get from one single tap on your dialog?

                      JoeCFDJ Online
                      JoeCFDJ Online
                      JoeCFD
                      wrote on last edited by
                      #10

                      @Pl45m4 A tap on screen does trigger QEvent::MouseButtonPress. That is why all other buttons on the main window work fine.

                      1 Reply Last reply
                      0
                      • JoeCFDJ Online
                        JoeCFDJ Online
                        JoeCFD
                        wrote on last edited by
                        #11

                        Still have not figured out how to let the pop-up dialog get focus. Any help?

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

                          Hi
                          I would try without the line
                          setWindowFlags((Qt::WindowFlags)(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint));
                          and see if still the same.

                          Also, i would qDebug()
                          QWidget *QApplication::focusWidget()
                          to see who got the focus then.

                          What platform is this on ?

                          JoeCFDJ 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            Hi
                            I would try without the line
                            setWindowFlags((Qt::WindowFlags)(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint));
                            and see if still the same.

                            Also, i would qDebug()
                            QWidget *QApplication::focusWidget()
                            to see who got the focus then.

                            What platform is this on ?

                            JoeCFDJ Online
                            JoeCFDJ Online
                            JoeCFD
                            wrote on last edited by
                            #13

                            @mrjj It is on Ubuntu. The flag settings are as follows:
                            setWindowFlags((Qt::WindowFlags)(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint));
                            I checked the focus widget which is on a button inside the main widget. The problem is why the pop-up dialog or its children can not get focus?

                            1 Reply Last reply
                            0
                            • X Offline
                              X Offline
                              xala_qt
                              wrote on last edited by
                              #14

                              Did you solve this problem, @JoeCFD ? I am having the same problem and starting to be a bit desperated. Thanks to all in advance.

                              1 Reply Last reply
                              0
                              • JoeCFDJ Online
                                JoeCFDJ Online
                                JoeCFD
                                wrote on last edited by
                                #15

                                Add event filter and handle press event. Then check event position and you know which button is clicked.

                                S 1 Reply Last reply
                                0
                                • JoeCFDJ JoeCFD

                                  Add event filter and handle press event. Then check event position and you know which button is clicked.

                                  S Offline
                                  S Offline
                                  swansorter
                                  wrote on last edited by swansorter
                                  #16

                                  @JoeCFD Not yet.Did you solve it?

                                  1 Reply Last reply
                                  0
                                  • X Offline
                                    X Offline
                                    xala_qt
                                    wrote on last edited by xala_qt
                                    #17

                                    @JoeCFD , @swansorter, I finally figured out what whas happening in my case. Since my touch screen is a capacitive one, I had to create my qdialog on mousereleaseevent, instead of on mousepressevent.

                                    1 Reply Last reply
                                    1

                                    • Login

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