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. QDockWidget icons are blurry and SP_TitleBar pixmaps are different sizes?

QDockWidget icons are blurry and SP_TitleBar pixmaps are different sizes?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 2.0k Views
  • 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.
  • L Offline
    L Offline
    lantern
    wrote on last edited by
    #1

    I want to use Dock Widgets, but on my hi-dpi screen the title bar icons are blurry. I assume its not blurry for other people?

    I made a test with this code in a mainWindow constructor and the icons were all different sizes. See here:

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    {
        QWidget *wid = new QWidget(this);
        QVBoxLayout *layout = new QVBoxLayout;
        wid->setLayout(layout);
    
        QStyle *style = this->style();
        QIcon closeIcon = style->standardIcon(QStyle::SP_TitleBarCloseButton);
        QIcon maxIcon = style->standardIcon(QStyle::SP_TitleBarMaxButton);
        QIcon minIcon = style->standardIcon(QStyle::SP_TitleBarMinButton);
        QIcon normalIcon = style->standardIcon(QStyle::SP_TitleBarNormalButton);
    
    
        qDebug() << closeIcon.availableSizes();
        qDebug() << maxIcon.availableSizes();
        qDebug() << minIcon.availableSizes();
        qDebug() << normalIcon.availableSizes();
    
        QPushButton *min = new QPushButton(this);
        QPushButton *max = new QPushButton(this);
        QPushButton *close = new QPushButton(this);
        QPushButton *normal = new QPushButton(this);
        min->setIcon(minIcon);
        max->setIcon(maxIcon);
        close->setIcon(closeIcon);
        normal->setIcon(normalIcon);
    
        layout->setSpacing(0);
        layout->addWidget(min);
        layout->addWidget(max);
        layout->addWidget(close);
        layout->addWidget(normal);
    
       wid->style()->standardIcon(QStyle::SP_DockWidgetCloseButton, nullptr, wid);
    
        setCentralWidget(wid);
    }
    

    Available sizes:
    (QSize(10, 10), QSize(16, 16), QSize(20, 20), QSize(32, 32), QSize(48, 48), QSize(64, 64))
    (QSize(10, 10))
    (QSize(10, 10))
    (QSize(10, 10), QSize(16, 16), QSize(20, 20), QSize(32, 32), QSize(48, 48), QSize(64, 64))

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

      What style do you use? The pixmaps are handled by the styles.

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

        The Default, Windows, im on Windows 10.

        If I switch it to Fusion the icons are not blurry, but are low-res pixelated.

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

          Mhh . what qt version do you use? From a short look at the code I would have expected that SP_TitleBarMinButton returns the same values as SP_TitleBarNormalButton/SP_TitleBarCloseButton ...

          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
          • L Offline
            L Offline
            lantern
            wrote on last edited by
            #5

            The latest version, 5.11.1. I would expect them to be the same too. I wonder If someone else runs that code there will it have the same sizes for icons.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lantern
              wrote on last edited by lantern
              #6

              Now I found another bug where you cant set the background-color of a dock widget to white. Any other color works, but not white. wtf

              dock->setStyleSheet("background-color: black;"); = works
              dock->setStyleSheet("background-color: white;"); = fails
              dock->setStyleSheet("background-color: #ffffff;"); = fails

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lantern
                wrote on last edited by lantern
                #7

                Alright, I found ways to fix all the issues that kept coming up, but its still a problem that the dock icons are not crisp.

                List of QDockWidget caveats / undocumented features:

                1. Floating dock windows has the Qt::Tool flag, which I find extremely ugly on windows 10, its got no border except for one line on top, the close icon icon has a gap off the top. I dont know where Windows itself uses this type of window, and I think QDockWidget should set floating window to Qt::Window, or give the option for it.
                  Heres the code, would not need much to allow customisation.
                Qt::WindowFlags flags = floating ? Qt::Tool : Qt::Widget;
                

                This is fixable with a workaround but I would prefer a method for it.
                See https://pastebin.com/raw/5u9mZ7cy

                1. Blurry icons, I override them with styles.
                QDockWidget {
                    titlebar-close-icon: url(cross.png);
                    titlebar-normal-icon: url(box.png);
                }
                

                It looks good except the close icon looks very slightly different from normal window close icon because the rendering must be different.

                1. Styles inconsistent, this was more because stylesheets are weird. This works:
                QDockWidget::title {
                    background: white;
                }
                
                1. QMainWindow::addDockWidget() is not set, it may seem to still work, but it causes buggy behavior. Can:
                • Prevent dock widget from being moveable.
                • When you drag it the first time dock widget does not change window flag , and it moves way away from the mouse.

                Main issues:

                • Windows 'Tool' windows suck, add ability to set window flags.
                • addDockWidget is undocumented in QDockWidget doc page since its a QMainWindow method, but its essential.
                1 Reply Last reply
                1
                • L Offline
                  L Offline
                  lantern
                  wrote on last edited by
                  #8

                  Alright, one more. Its undocumented that if you dare use a widget without minimumSizeHint re-implemented as the setWidget of QDockWidget, it will cause an unslightly visual glitch when you try to dock it to a space where it shouldnt be able to fit.

                  So a QWidget or QFrame will 100% everytime glitch visually.

                  0_1535497818191_dockGlitch.png

                  Example of size hints that fix the issue (must have at least minimumSizeHint)
                  https://pastebin.com/raw/TPa3E47i

                  You may also see how the dock icons are not crisp, but the image resolution makes them look less bad than they are.

                  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