QDockWidget icons are blurry and SP_TitleBar pixmaps are different sizes?
-
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)) -
What style do you use? The pixmaps are handled by the styles.
-
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 ...
-
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 -
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:
- 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- 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.
- Styles inconsistent, this was more because stylesheets are weird. This works:
QDockWidget::title { background: white; }
- 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.
- 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.
-
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.
Example of size hints that fix the issue (must have at least minimumSizeHint)
https://pastebin.com/raw/TPa3E47iYou may also see how the dock icons are not crisp, but the image resolution makes them look less bad than they are.