Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

popup modal dialog does not have focus on touch screen



  • 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?



  • @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()?



  • Still not figured out. Any help?



  • 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?



  • @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.


  • Qt Champions 2019

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



  • @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.



  • @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.



  • 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.



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



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


  • Lifetime Qt Champion

    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 ?



  • @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?


Log in to reply