QMessageBox Buttons Become Unclickable on Android When Applying Stylesheet
-
On Android, applying a stylesheet to any widget (not just QMessageBox) makes QMessageBox buttons unclickable. Even setting an empty stylesheet on any widget causes this issue.
Steps to Reproduce
Create a QMessageBox and display it normally.QMessageBox::StandardButton reply; reply = QMessageBox::question(this, tr("Test"), tr("Clickable?"), QMessageBox::Yes | QMessageBox::No);
The buttons are clickable as expected.
Apply any styleSheet to any widget and the buttons become unclickable on Android. Windows build is fine - no issues.
Even applying an empty rule breaks interactivityvoid MainWindow::on_pushButton_clicked() { //if next line is uncommented QMessageBox becomes unclickable // setStyleSheet("QMessageBox { }"); /this makes QMessageBox unclickable QMessageBox::StandardButton reply; reply = QMessageBox::question(this, tr("Test "), tr("Clickable?"), QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes){ //if uncomment next line next QMessageBox becomes unclickable //setStyleSheet("QPushButton { }"); //this makes QMessageBox unclickable as well QMessageBox::information(this,"Check it","StyleSheet is set. Is it clickable?" ); } }
Tested on Qt Version: [6.8.1] and [6.8.2]
OS: Android 13
Build Android Qt 6.8.2 Clang arm64-v8aWorkarounds Tried
Setting setFocus() and repaint() on QMessageBox - no effect.
Applying the style globally via qApp->setStyleSheet() - no effect. -
Hi @jsulm !
It is a dark mode for my app. Stylesheet inverts colors. Everething works fine until QMessageBox pops up. Windows build works fine, this problem appears only on AndroidSomething as follows
void MainWindow::toggleDarkMode() { isDarkMode = !isDarkMode; if(isDarkMode) { setStyleSheet("QMainWindow { background-color: #2E2E2E; color: white; }" "QLabel, QPushButton, QCheckBox, QToolButton, QListWidget, QWidget { color: white; }" "QPushButton, QToolButton, QListWidget { background-color: #555; border: 1px solid white; }" "QLineEdit { background-color: #444; color: white; border: 1px solid white; }" "QMessageBox { background-color: #2E2E2E; color: white; }" "QMessageBox QLabel { color: white; }" "QMessageBox QPushButton { background-color: #555; color: white; border: 1px solid white; }" "QComboBox { background-color: #444; color: white; border: 1px solid white; }" "QComboBox QAbstractItemView { background-color: #333; color: white; }"); //invert images //QPixmap pixmap(":/images/my_image.png"); // Load original image QImage img = Compass.toImage(); img.invertPixels(QImage::InvertRgb); // Invert colors ui->labelCompass->setPixmap(QPixmap::fromImage(img)); img = Clock.toImage(); img.invertPixels(QImage::InvertRgb); // Invert colors ui->labelClock->setPixmap(QPixmap::fromImage(img)); //invert button icons invertButtonIcon(ui->windDirectionSelector1of3PushButton); invertButtonIcon(ui->windDirectionSelector2of3PushButton); invertButtonIcon(ui->windDirectionSelector3of3PushButton); invertButtonIcon(ui->singleWindDirectionSelectorPushButton); //applyDarkModeToPlot(ui->plotWidget); }else{ setStyleSheet(""); // Reset to default ui->labelCompass->setPixmap(QPixmap(":/img/compass.jpg")); ui->labelClock->setPixmap(QPixmap(":/img/clock.png")); invertButtonIcon(ui->windDirectionSelector1of3PushButton); invertButtonIcon(ui->windDirectionSelector2of3PushButton); invertButtonIcon(ui->windDirectionSelector3of3PushButton); invertButtonIcon(ui->singleWindDirectionSelectorPushButton); //applyLightModeToPlot(ui->plotWidget); } }
-
Could you please check if my minimal compilable example provided by the link has a behavior as described?
https://drive.google.com/file/d/1JBucqsDPNZYun_3XvONqfA810eJ2my-c/view?usp=drive_link -
So here is my findings. Maybe someone can give me a hint
Applying any styleSheet on Android shifts Z-order of QMessageBox which makes its buttons unclickableHere what is going on:
//setting styleSheet to any widget breaks interactivity on Android setStyleSheet("QPushButton { }"); QMessageBox::information(this,"Check the message", "Is it clickable?" ); //it is not clickable on Android
But if we manually set Z-order to the message this message becomes clickable. But further ones ARE NOT
setStyleSheet("QPushButton { }"); //applying styleSheet QMessageBox msgBox; msgBox.setText("StyleSheet is set. Z-order fixed"); //set stayOnTop flag and it becomes clickable msgBox.setWindowFlags(Qt::Dialog | Qt::WindowStaysOnTopHint); msgBox.exec(); //Next message is unclickable QMessageBox::information(this,"Check next message", "Is it clickable?" ); //No it is not clickable
How to restore correct Z-order for all of my windows and messages after apllying a styleSheet in Android?