QLabel underline for accelerator doesn't update when Alt is pressed
-
Starting from Windows 10, the underline for accelerator (set by ampersand) is visible after Alt is pressed with default settings. I tested this with
QMenu
and it worked well. However forQLabel
, the underline didn't show, even after I changed system settings. But it's visible after recreating the widget object. Then I realized that probably that's because there's no update slot to updateQLabel
when accelerator is activated. Is there anyway to fix this bug? Thanks. -
Please provide a minimal, compileable example of the problem. Also the exact Qt version and style you are using.
-
Environment
Qt: v6.8.1 (mingw_64)
Windows 11Minimal Example
Problem
When the program is running, toggle "Underline keyboard short cuts and keys" in "Control Panel\Ease of Access\Ease of Access Center\Make the keyboard easier to use". The label doesn't update the underline, until the program is exited and restarted.
QMenu
can update this without restarting the program. ProbablyQLabel
doesn't have a slot to update display when this system setting changes.
Code
My code is recognized as spam and prohibited from posting here. I'll attach download link.
https://drive.google.com/file/d/18V_E4UvpG2e9h9MDhHR_YLOanw9t_leJ/view?usp=sharing
The key part isMainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { lineEdit1 = new QLineEdit; lineEdit2 = new QLineEdit; // bug: QLabel underline for accelerator doesn't update when Alt is pressed in Windows label1 = new QLabel(tr("Field &A:")); label1->setBuddy(lineEdit1); label2 = new QLabel(tr("Field &B:")); label2->setBuddy(lineEdit2); QWidget *centralWidget = new QWidget; setCentralWidget(centralWidget); QGridLayout *mainLayout = new QGridLayout(centralWidget); mainLayout->addWidget(label1, 0, 0); mainLayout->addWidget(lineEdit1, 0, 1); mainLayout->addWidget(label2, 1, 0); mainLayout->addWidget(lineEdit2, 1, 1); menuBar()->addMenu(tr("&Menu")); }