Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QMessageBox Buttons Become Unclickable on Android When Applying Stylesheet
QtWS25 Last Chance

QMessageBox Buttons Become Unclickable on Android When Applying Stylesheet

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
unclickableandroid buttonsstylesheets
6 Posts 2 Posters 235 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.
  • Z Offline
    Z Offline
    zvoopz
    wrote on last edited by
    #1

    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 interactivity

    void 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-v8a

    Workarounds Tried
    Setting setFocus() and repaint() on QMessageBox - no effect.
    Applying the style globally via qApp->setStyleSheet() - no effect.

    jsulmJ 1 Reply Last reply
    0
    • Z zvoopz

      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 interactivity

      void 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-v8a

      Workarounds Tried
      Setting setFocus() and repaint() on QMessageBox - no effect.
      Applying the style globally via qApp->setStyleSheet() - no effect.

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

      @zvoopz How does the style sheet look like?

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

      Z 1 Reply Last reply
      0
      • jsulmJ jsulm

        @zvoopz How does the style sheet look like?

        Z Offline
        Z Offline
        zvoopz
        wrote on last edited by zvoopz
        #3

        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 Android

        Something 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);
            }
        }
        

        view screenshot

        Z 1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zvoopz
          wrote on last edited by
          #4

          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

          jsulmJ 1 Reply Last reply
          0
          • Z zvoopz

            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

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

            @zvoopz No, I don't have development environment for Android at hand right now.
            Maybe will do this evening.

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

            1 Reply Last reply
            0
            • Z zvoopz

              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 Android

              Something 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);
                  }
              }
              

              view screenshot

              Z Offline
              Z Offline
              zvoopz
              wrote on last edited by
              #6

              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 unclickable

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

              1 Reply Last reply
              0

              • Login

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