AccessibleName for QPushButton stopped working in the 6.9.2 with the QTabWidget
-
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?
@Olex said in AccessibleName for QPushButton stopped working in the 6.9.2 with the QTabWidget:
Why did this happen? What is the cause?
You will find it out when you minimize your code until the problem goes away... I won't do it for you, I already showed you that it is working fine.
-
I didn't ask you do any thing for me and won't ask. And you haven't showed that parameter "accessibleName" from ui file file works fine :(. You just showed how you can get around the problem.
@Olex said in AccessibleName for QPushButton stopped working in the 6.9.2 with the QTabWidget:
And you haven't showed that parameter "accessibleName" from ui file file works fine
Qt Designer saves a
.ui
file. When you "build" a Qt program,uic
, is run on the.ui
file. That produces a C++ source/header file, namedui_....h
and placed in the build output directory. You include it in your.cpp
via a#include
.So the
.ui
has no special significance. It is not used at runtime. Go look in that file to see what it does for theaccessibleName
you set in Designer --- I'm guessing it's something like code for creating aQObject
property on the widget. Whatever you can work from there. It means the.ui
cannot "affect" anything directly, everything it contains is turned into C++ code in theui_....h
file. -
Thanks. I understand.
It must work such way. I went, for example, to "debug" folder and read ui_mainwindow.h file. And checked: "btn1->setAccessibleName(QCoreApplication::translate("MainWindow", "btn_1", nullptr));" - It's fine. And it doesn't work.
But then I moved "btn1->setAccessibleName" to the "setupUi" function and it started working. Thank you. It gave some understanding about cause of the problem and made easier to work with it. And it seems that the cause is some update in Qt 6.9.2 :(. -
Thanks. I understand.
It must work such way. I went, for example, to "debug" folder and read ui_mainwindow.h file. And checked: "btn1->setAccessibleName(QCoreApplication::translate("MainWindow", "btn_1", nullptr));" - It's fine. And it doesn't work.
But then I moved "btn1->setAccessibleName" to the "setupUi" function and it started working. Thank you. It gave some understanding about cause of the problem and made easier to work with it. And it seems that the cause is some update in Qt 6.9.2 :(.@Olex said in AccessibleName for QPushButton stopped working in the 6.9.2 with the QTabWidget:
And it doesn't work.
But then I moved "btn1->setAccessibleName" to the "setupUi" function and it started working.Hmm, that's interesting. There will be some reason for this --- the generated stuff must do it too early, perhaps because of something in your case, so it gets "lost" while you doing it explicitly again later makes it work. Do not attempt to change the generated
ui_....h
file! Have you done that from what you say? That is no good, as the file will be regenerated when you next change the.ui
file and any changes you make will be lost. You can put your own "extras" in after the call tosetupUi()
. As you have found, it can sometimes be useful to examine that file to understand what is going on. -
Thank you. I understand these things - how files are generated by qt. I created a few test case programs to investigate this and have a very stable result. It doesn't work with the TabWidget and not only with the buttons but with, I suspect, every qwidget. I checked some of them.
Yes, completely agree. And it useful to understand and to check ui h file :( -
Maybe due to the translation of the property. As I already said - you are misusing this property for styling. This is wrong in the beginning.
But you refuse to find the culprit so I won't comment here further -
-
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_NAMESPACEclass MainWindow : public QMainWindow
{
Q_OBJECTpublic:
MainWindow(QWidget *parent = nullptr);
~MainWindow();private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_Hmainwindow.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>@Olex said in AccessibleName for QPushButton stopped working in the 6.9.2 with the QTabWidget:
Style from style.qss (for example, background color) doesn't apply for Button 1
QPushButton[accessibleName="btn_1"]
{
background-color: #9afc9d;I believe what @Christian-Ehrlicher is saying is that the accessibleName property of a widget is not supposed to be usable/used for styling, such as you are doing in a CSS rule. For one thing the text gets localized, so that would break. It may have worked before but for some reason it does not now, but it's not supported.
Please don't shoot me if I am wrong.
If you really want to know what alone has changed between 6.9.1 and 6.9.2 compare the
.ui
files produced by each. If they have not changed in any important way then perhaps the difference in behaviour is in different Qt versions rather than the Designer. -
I don't have machine gun :). Yes, of course, it may not be supported, I can't argue. I haven't read from @Christian-Ehrlicher that it's not supported :). And I haven't find anything about supporting or not particularly this case in Qt documentation (except inet full of examples).
What has changed int 6.9.2? After upgrade from 6.9.1 to 6.9.2 just recompile in 6.9.1 gave nothing. It needs a little more time and more efforts to investigate. I'll do it a little later.
-
And I fixed it under 6.9.2. The cause is in "app.setStyleSheet(styleSheet); " position in the main.cpp file :). I'm surprised why it worked so long in previous Qt versions :).
It was (style issue):
app.setStyleSheet(styleSheet); MainWindow win; win.show();
The problem is predictable :(
It needs to be:
MainWindow win; app.setStyleSheet(styleSheet); win.show();
It's more logical. Firstly create GUI, then apply style :)
I think, the problem has resolved.
-