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 aboutraise/activate/focus
, assuming you need them for the behaviour you want, would not have any effect until a window/dialog isshow()
n, and therefore does not belong in the constructor: rather should be in something like theQDialog::showEvent()
? -
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 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
?
IfRaise
,Focus
and so on are connected to the QMouseEvent and not to theQTouchEvent
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. -
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?