1

I found that my QMessageBox was not responding to touch events whenever the Qt::FramelessWindowHint window flag is set. When cleared, the dialog responds normally.

After some additional testing, I found that the touch DOES work, but it is registering the coordinates of the buttons in the wrong place on the window. The QMessageBox is drawn centered on the screen, but it appears that the OS thinks that the dialog is positioned in the upper-left hand corner of the screen. (e.g. I have to touch the upper-left corner of the message box to click the buttons which are actually located at the bottom in the center of the window).

My guess is that there is something going on with the touch calibration for the window. Is there any way to adjust this to compensate?

Does anyone know of a viable workaround for this? I'm developing my Qt application to run on a Raspberry PI 3. Either I need some way to counteract the coordinate offset, or I need a different way to make the window look frameless (I don't want the title bar and buttons displayed at the top).

For those interested in reproducing the problem. You can run this simple code to see the effect:

Test Application:

main.cpp

#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QMessageBox>

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

    QMessageBox box;
    box.setText("box");
    box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
    box.setWindowFlags(Qt::FramelessWindowHint);
    box.exec();
}
MainWindow::~MainWindow()
{
    delete ui;
}

This example will work fine with using the mouse to dismiss the dialog, but using touch, it does not work.

NOTE: There is a bug filed with Qt concerning this problem. The code example above was taken from the bug report. Here's the link here for those interested: QTBUG-47474: frameless QMessageBox: Buttons not usable via Touchscreen

Jason O
  • 753
  • 9
  • 28
  • Yes, I did get that code from the bug. I was hoping to find some kind of workaround for it until they can fix it. I'll add a note to the post so people know I'm aware of it too. – Jason O May 20 '21 at 16:50
  • If you're looking for a work-around I would derive the class in quest and overload the resp. event handler(s). Probably there is something broken to translate global mouse pos into local but this should be quite easy to fix. If deriving is not an option, an event filter could be used as well. Alternatively, you could have a look onto the resp. classes (Qt is open source) and suggest a fix. – Scheff's Cat May 20 '21 at 16:57

0 Answers0