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. How do I get a QMenu to react to text size changes on High DPI diplays
Forum Updated to NodeBB v4.3 + New Features

How do I get a QMenu to react to text size changes on High DPI diplays

Scheduled Pinned Locked Moved General and Desktop
hdpiwindowsqt5.5
1 Posts 1 Posters 1.0k 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.
  • M Offline
    M Offline
    mikag
    wrote on last edited by
    #1

    The text in menubars and menues automatically change size when a window is moved from a 96 dpi screen to 192 dpi screen. I naively thought Qt would automatically resize menues when the menu text size changed but I'm obviously wrong here.

    1. How can I get QMenuBar and QMenu to change size when the text changes size? (Specifically when the window is dragged to the 192 dpi screen)

    Text size only change when I move the window to a 192 dpi screen. If the window is initially shown on the 192 screen it will draw the smaller 96 dpi text.

    1. How do I ensure that the text is the correct size when the mainwindow opens on a 192 dpi screen?

    I've tested playing around with the QT_DEVICE_PIXEL_RATIO env variable but this doesn't solve anything. I can force the menues to become larger by setting the value to 2, but I need them to change size depending on the screen in use. And the application must be Per-Monitor DPI Aware on Windows so leaving it to the window manager auto scale is not an option.

    I've also tested this with the Fusion style to rule out it being related to the native Windows style.
    Menues
    (Just noticed the 192 dpi image is actually at 144 dpi, the 192 dpi version looks worse..)

    A trivial test case:

    #include <QMainWindow>
    #include <QMenuBar>
    #include <QStyle>
    //#include <QStyleFactory>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        //a.setStyle((QStyleFactory::create(("Fusion"))));
    
        QMainWindow w;
    
        QMenuBar *menuBar = w.menuBar();
    
        QMenu *menuFile = menuBar->addMenu("File");
        QMenu *menuEdit = menuBar->addMenu("Edit");
        QMenu *menuCompany = menuBar->addMenu("&Company");
        QMenu *menuArrange = menuBar->addMenu("Arrange");
    
        // file menu
        menuFile->addAction(a.style()->standardIcon(QStyle::SP_DirOpenIcon), "Open", nullptr, nullptr, QKeySequence::Open);
        menuFile->addAction(a.style()->standardIcon(QStyle::SP_DriveFDIcon), "Save", nullptr, nullptr, QKeySequence::Save);
        QAction* actionQuit = menuFile->addAction("Quit");
        QObject::connect(actionQuit, &QAction::triggered, &w, &QMainWindow::close);
        // edit menu
        menuEdit->addAction(a.style()->standardIcon(QStyle::SP_ArrowLeft), "Undo", nullptr, nullptr, QKeySequence::Undo);
        menuEdit->addAction(a.style()->standardIcon(QStyle::SP_ArrowRight), "Redo", nullptr, nullptr, QKeySequence::Redo);
        // company menu
        menuCompany->addAction(a.style()->standardIcon(QStyle::SP_DriveNetIcon), "DB Connect", nullptr, nullptr, QKeySequence(Qt::SHIFT + Qt::Key_Insert));
    
        w.setCentralWidget(new QWidget);
    
        w.show();
    
        return a.exec();
    }
    

    Tested on Windows 8.1 with Qt 5.4 & 5.5. All dpi values are what Windows reports, not the actual physical screen dpi.
    I'm hoping to find a non native solution to this but I don't really know if this is an issue on any other platform then Windows.

    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