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. QLabel underline for accelerator doesn't update when Alt is pressed
Forum Updated to NodeBB v4.3 + New Features

QLabel underline for accelerator doesn't update when Alt is pressed

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 229 Views 1 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.
  • T Offline
    T Offline
    thinkinmachine
    wrote on last edited by
    #1

    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 for QLabel, 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 update QLabel when accelerator is activated. Is there anyway to fix this bug? Thanks.

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

      Please provide a minimal, compileable example of the problem. Also the exact Qt version and style you are using.

      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
      • T Offline
        T Offline
        thinkinmachine
        wrote on last edited by thinkinmachine
        #3

        Environment

        Qt: v6.8.1 (mingw_64)
        Windows 11

        Minimal 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. Probably QLabel doesn't have a slot to update display when this system setting changes.
        a7032481-d29c-4456-83cc-e09d169cf0a2-image.png

        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 is

        MainWindow::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"));
        }
        
        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