Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. AccessibleName for QPushButton stopped working in the 6.9.2 with the QTabWidget
Forum Updated to NodeBB v4.3 + New Features

AccessibleName for QPushButton stopped working in the 6.9.2 with the QTabWidget

Scheduled Pinned Locked Moved Solved General and Desktop
32 Posts 5 Posters 727 Views 2 Watching
  • 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.
  • O Offline
    O Offline
    Olex
    wrote last edited by
    #1

    AccessibleName for QPushButton stopped working in the 6.9.2 with the QTabWidget (for first page).
    It works perfect for 6.9.1 and earlier.
    Style from style.qss (for example, background color) doesn't apply for Button 1 in the first page of the QTabWidget, but it works for Button 2 on the second page.

    Program code (simplest program):

    main.cpp:

    #include "mainwindow.h"

    #include <QApplication>
    #include <QFile>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QFile styleFile(":/res/stylesheet.qss");
    

    #ifdef QT_DEBUG
    bool ret =
    #endif // QT_DEBUG
    styleFile.open(QFile::ReadOnly);
    #ifdef QT_DEBUG
    qDebug() << "\nMain function (app starts): styleFile.open = " << ret << "\n";
    #endif // QT_DEBUG
    QString styleSheet = QLatin1String(styleFile.readAll());
    app.setStyleSheet(styleSheet);

    MainWindow win;
    win.show();
    return app.exec();
    

    }

    mainwindow.h:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    QT_BEGIN_NAMESPACE
    namespace Ui {
    class MainWindow;
    }
    QT_END_NAMESPACE

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    };
    #endif // MAINWINDOW_H

    mainwindow.cpp:

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

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

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    stylesheet.qss:

    QPushButton[accessibleName="btn_1"]
    {
    background-color: #9afc9d;
    color: #000000;
    border: 1px solid #728773;
    border-radius: 6px;
    }

    QPushButton[accessibleName="btn_2"]
    {
    background-color: #0afc9d;
    color: #000000;
    border: 1px solid #728773;
    border-radius: 6px;
    }

    mainwindow.ui:

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>MainWindow</string>
    </property>
    <widget class="QWidget" name="centralwidget">
    <widget class="QTabWidget" name="tabWidget">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>140</y>
    <width>751</width>
    <height>131</height>
    </rect>
    </property>
    <property name="currentIndex">
    <number>1</number>
    </property>
    <widget class="QWidget" name="tab">
    <attribute name="title">
    <string>Tab 1</string>
    </attribute>
    <widget class="QPushButton" name="btn1">
    <property name="geometry">
    <rect>
    <x>60</x>
    <y>40</y>
    <width>80</width>
    <height>25</height>
    </rect>
    </property>
    <property name="accessibleName">
    <string>btn_1</string>
    </property>
    <property name="text">
    <string>Button 1</string>
    </property>
    </widget>
    </widget>
    <widget class="QWidget" name="tab_2">
    <attribute name="title">
    <string>Tab 2</string>
    </attribute>
    <widget class="QPushButton" name="btn2">
    <property name="geometry">
    <rect>
    <x>130</x>
    <y>40</y>
    <width>80</width>
    <height>25</height>
    </rect>
    </property>
    <property name="accessibleName">
    <string>btn_2</string>
    </property>
    <property name="text">
    <string>Button 2</string>
    </property>
    </widget>
    </widget>
    </widget>
    </widget>
    <widget class="QMenuBar" name="menubar">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>22</height>
    </rect>
    </property>
    </widget>
    <widget class="QStatusBar" name="statusbar"/>
    </widget>
    <resources/>
    <connections/>
    </ui>

    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      Which OS are you on ?
      What are you using for assistive backend ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • O Offline
        O Offline
        Olex
        wrote last edited by
        #3

        Hi.
        Windows.
        Sorry, didn't understand "assistive backend". Qt creator? Qt Creator 17.0.1

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote last edited by
          #4

          What software are you using for accessibility ?
          macOS as built-in support
          There's NVDA for Windows
          Orca for Linux
          Those are just some example from memory, things may have changed since they were common.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • O Offline
            O Offline
            Olex
            wrote last edited by
            #5

            Narrator in Windows 11. Tested the same code on other computer - 6.9.1 woks, 6.9.2 - doesn't :(

            1 Reply Last reply
            0
            • O Offline
              O Offline
              Olex
              wrote last edited by
              #6

              I have pretty simple code that worked many years on Windows 10 and Windows 11 in Qt 5 and Qt 6 - except Qt 6.9.2 :(

              1 Reply Last reply
              0
              • O Offline
                O Offline
                Olex
                wrote last edited by
                #7

                I suspect there's not any relations to "software for accessibility". It's about QWidget parameter "accessiblename" and style.qss file from program's resource cooperation.

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote last edited by
                  #8

                  Please provide a minimal, compilable example (from what I see it should fit into 20 lines in a single main.cpp) so we can take a look on what you are trying to do and what's no longer working. Looks like you mis-use accessibleName property to modify the style of your widgets but I'm not sure.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    Olex
                    wrote last edited by Olex
                    #9

                    *# .pro:

                    QT += core gui

                    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

                    CONFIG += c++17

                    You can make your code fail to compile if it uses deprecated APIs.

                    In order to do so, uncomment the following line.

                    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

                    SOURCES +=
                    main.cpp
                    mainwindow.cpp

                    HEADERS +=
                    mainwindow.h

                    FORMS +=
                    mainwindow.ui

                    Default rules for deployment.

                    qnx: target.path = /tmp/$${TARGET}/bin
                    else: unix:!android: target.path = /opt/$${TARGET}/bin
                    !isEmpty(target.path): INSTALLS += target

                    RESOURCES +=
                    resource.qrc

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      Olex
                      wrote last edited by Olex
                      #10

                      # main.cpp:

                      #include "mainwindow.h"

                      #include <QApplication>
                      #include <QFile>

                      int main(int argc, char *argv[])
                      {
                      QApplication app(argc, argv);

                      QFile styleFile(":/res/stylesheet.qss");
                      bool ret = styleFile.open(QFile::ReadOnly);
                      qDebug() << "\nMain function (app starts): styleFile.open = " << ret << "\n";
                      QString styleSheet = QLatin1String(styleFile.readAll());
                      app.setStyleSheet(styleSheet);
                      
                      MainWindow win;
                      win.show();
                      return app.exec();
                      

                      }

                      ====================================================

                      # mainwindow.h:

                      #ifndef MAINWINDOW_H
                      #define MAINWINDOW_H

                      #include <QMainWindow>

                      QT_BEGIN_NAMESPACE
                      namespace Ui {
                      class MainWindow;
                      }
                      QT_END_NAMESPACE

                      class MainWindow : public QMainWindow
                      {
                      Q_OBJECT

                      public:
                      MainWindow(QWidget *parent = nullptr);
                      ~MainWindow();

                      private:
                      Ui::MainWindow *ui;
                      };
                      #endif // MAINWINDOW_H

                      ====================================================

                      # mainwindow.cpp:

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

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

                      MainWindow::~MainWindow()
                      {
                      delete ui;
                      }

                      ====================================================

                      # mainwindow.ui:

                      <?xml version="1.0" encoding="UTF-8"?>
                      <ui version="4.0">
                      <class>MainWindow</class>
                      <widget class="QMainWindow" name="MainWindow">
                      <property name="geometry">
                      <rect>
                      <x>0</x>
                      <y>0</y>
                      <width>800</width>
                      <height>600</height>
                      </rect>
                      </property>
                      <property name="windowTitle">
                      <string>MainWindow</string>
                      </property>
                      <widget class="QWidget" name="centralwidget">
                      <widget class="QTabWidget" name="tabWidget">
                      <property name="geometry">
                      <rect>
                      <x>20</x>
                      <y>140</y>
                      <width>751</width>
                      <height>131</height>
                      </rect>
                      </property>
                      <property name="currentIndex">
                      <number>1</number>
                      </property>
                      <widget class="QWidget" name="tab">
                      <attribute name="title">
                      <string>Tab 1</string>
                      </attribute>
                      <widget class="QPushButton" name="btn1">
                      <property name="geometry">
                      <rect>
                      <x>60</x>
                      <y>40</y>
                      <width>80</width>
                      <height>25</height>
                      </rect>
                      </property>
                      <property name="accessibleName">
                      <string>btn_1</string>
                      </property>
                      <property name="text">
                      <string>Button 1</string>
                      </property>
                      </widget>
                      </widget>
                      <widget class="QWidget" name="tab_2">
                      <attribute name="title">
                      <string>Tab 2</string>
                      </attribute>
                      <widget class="QPushButton" name="btn2">
                      <property name="geometry">
                      <rect>
                      <x>130</x>
                      <y>40</y>
                      <width>80</width>
                      <height>25</height>
                      </rect>
                      </property>
                      <property name="accessibleName">
                      <string>btn_2</string>
                      </property>
                      <property name="text">
                      <string>Button 2</string>
                      </property>
                      </widget>
                      </widget>
                      </widget>
                      </widget>
                      <widget class="QMenuBar" name="menubar">
                      <property name="geometry">
                      <rect>
                      <x>0</x>
                      <y>0</y>
                      <width>800</width>
                      <height>22</height>
                      </rect>
                      </property>
                      </widget>
                      <widget class="QStatusBar" name="statusbar"/>
                      </widget>
                      <resources/>
                      <connections/>
                      </ui>

                      ====================================================

                      # stylesheet.qss:

                      QPushButton[accessibleName="btn_1"]
                      {
                      background-color: #9afc9d;
                      color: #000000;
                      border: 1px solid #728773;
                      border-radius: 6px;
                      }

                      QPushButton[accessibleName="btn_2"]
                      {
                      background-color: #0afc9d;
                      color: #000000;
                      border: 1px solid #728773;
                      border-radius: 6px;
                      }

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote last edited by
                        #11

                        These are more than 20 lines and even ore than one file.
                        Reduce your testcase if you want me to look at it.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0
                        • O Offline
                          O Offline
                          Olex
                          wrote last edited by Olex
                          #12

                          Sorry, it's not a console application. It has ui file and class MainWindow. I don't see possibility to make them in one file less than 20 lines. And I'm interested exactly in using style.qss file.

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote last edited by Christian Ehrlicher
                            #13

                            Oh sorry, not 20 lines but 23:

                            #include <QtWidgets>
                            
                            int main(int argc, char** argv)
                            {
                                QApplication app(argc, argv);
                                app.setStyleSheet(R"(
                            QPushButton[accessibleName="btn_1"]
                            { background-color: #9afc9d; }
                            QPushButton[accessibleName="btn_2"]
                            { background-color: #0afc9d; }
                            )");
                                QWidget w;
                                QVBoxLayout* lay = new QVBoxLayout(&w);
                                auto pb1 = new QPushButton("Push me once");
                                pb1->setAccessibleName("btn_1");
                                auto pb2 = new QPushButton("Push me twice");
                                pb2->setAccessibleName("btn_2");
                                lay->addWidget(pb1);
                                lay->addWidget(pb2);
                                w.show();
                                return app.exec();
                            }
                            

                            This is working fine for me with current Qt from git with windows/windowsvista/windows11 and fusion style:
                            dd6a8260-bce7-4425-8fc6-69e69e8b22dc-grafik.png

                            /edit: Installed 6.9.2 with the online installer and also works as expected.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            1 Reply Last reply
                            0
                            • O Offline
                              O Offline
                              Olex
                              wrote last edited by
                              #14

                              Yes, it works in this case. There is not a tabwidget with at list two pages. I added it and it works. Thanks. But it doesn't work with the ui (xml file) and qt widgets application.

                              1 Reply Last reply
                              0
                              • Christian EhrlicherC Offline
                                Christian EhrlicherC Offline
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote last edited by
                                #15

                                This is also working fine:

                                int main(int argc, char** argv)
                                {
                                    QApplication app(argc, argv);
                                    app.setStyleSheet(R"(
                                QPushButton[accessibleName="btn_1"]
                                { background-color: #9afc9d; }
                                QPushButton[accessibleName="btn_2"]
                                { background-color: #0afc9d; }
                                )");
                                    QMainWindow mw;
                                    auto tw = new QTabWidget;
                                    mw.setCentralWidget(tw);
                                    auto w = new QWidget;
                                    tw->addTab(w, "Tab");
                                    QVBoxLayout* lay = new QVBoxLayout(w);
                                    auto pb1 = new QPushButton("Push me once");
                                    pb1->setAccessibleName("btn_1");
                                    auto pb2 = new QPushButton("Push me twice");
                                    pb2->setAccessibleName("btn_2");
                                    lay->addWidget(pb1);
                                    lay->addWidget(pb2);
                                    mw.show();
                                    return app.exec();
                                }
                                

                                Please provide a minimal, compilable example to reproduce the problem.

                                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                Visit the Qt Academy at https://academy.qt.io/catalog

                                1 Reply Last reply
                                0
                                • O Offline
                                  O Offline
                                  Olex
                                  wrote last edited by
                                  #16

                                  I added it before and it works. But this code doesn't reproduce the problem :(

                                  #include <QApplication>
                                  #include <QMainWindow>
                                  #include <QtWidgets>

                                  int main(int argc, char** argv)
                                  {
                                  QApplication app(argc, argv);

                                  app.setStyleSheet(R"(
                                  

                                  QPushButton[accessibleName="btn_1"]
                                  { background-color: #9afc9d; }
                                  QPushButton[accessibleName="btn_2"]
                                  { background-color: #0afc9d; }
                                  )");

                                  QMainWindow win;
                                  QWidget cw(&win);
                                  win.setCentralWidget(&cw);
                                  
                                  QTabWidget tw(&cw);
                                  QWidget w1;
                                  tw.addTab(&w1, "1");
                                  QVBoxLayout* lay1 = new QVBoxLayout(&w1);
                                  auto pb1 = new QPushButton("Push me once", &w1);
                                  pb1->setAccessibleName("btn_1");
                                  lay1->addWidget(pb1);
                                  
                                  QWidget w2;
                                  tw.addTab(&w2, "2");
                                  QVBoxLayout* lay2 = new QVBoxLayout(&w2);
                                  auto pb2 = new QPushButton("Push me twice", &w2);
                                  pb2->setAccessibleName("btn_2");
                                  lay2->addWidget(pb2);
                                  
                                  win.show();
                                  
                                  return app.exec();
                                  

                                  }

                                  Thanks. Sorry, I provide example earlier. It reproduces the problem.

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    SimonSchroeder
                                    wrote last edited by
                                    #17

                                    Maybe have a look at the generated ui_mainwindow.h file. You need to figure out what is different between the example without the ui-file and with the ui-file. The ui-file just gets translated to regular C++ code.

                                    1 Reply Last reply
                                    1
                                    • O Offline
                                      O Offline
                                      Olex
                                      wrote last edited by
                                      #18

                                      Thanks. There is no any unusual :(. It worked for years. UI file created by qt designer:

                                      <widget class="QPushButton" name="btn1">
                                      <property name="geometry">
                                      <rect>
                                      <x>60</x>
                                      <y>40</y>
                                      <width>80</width>
                                      <height>25</height>
                                      </rect>
                                      </property>
                                      <property name="accessibleName">
                                      <string>btn_1</string>
                                      </property>
                                      <property name="text">
                                      <string>Button 1</string>
                                      </property>
                                      </widget>

                                      Just "accessibleName". And it works for second page of the TabWidget.

                                      1 Reply Last reply
                                      0
                                      • Christian EhrlicherC Offline
                                        Christian EhrlicherC Offline
                                        Christian Ehrlicher
                                        Lifetime Qt Champion
                                        wrote last edited by
                                        #19

                                        I still don't understand what's the problem minimizing your code until the problem goes away... The ui file is also only c++ code so move it to your cpp and reduce it. Daily business of a programmer.

                                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                        Visit the Qt Academy at https://academy.qt.io/catalog

                                        1 Reply Last reply
                                        0
                                        • O Offline
                                          O Offline
                                          Olex
                                          wrote last edited by
                                          #20

                                          The problem isn't in minimizing my code :(. The question is about this issue. Why did this happen? What is the cause? It's not about my code. I'll figure out what to do to fix it. I want to figure out why it happened. It mustn't be such issue, but it exists in 6.9.2 exactly. And when and where will the problem with the "accessibleName" happen next time? Always move parameter "accessibleName" to c++ code? Will it work if ui file has more complex GUI?

                                          Christian EhrlicherC 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