QDockWidget sizing borders
-
Recent builds of my code a detached QDockWidget seems not to have sizing borders.
Any ideas what I may have done? Or ??? This doesn't appear to be simply reproducible with the dockwidgets sample code.
For extra points if I can get the sizing border back, how can I make it larger than 1 pixel which is WAY too small for a 4K monitor
Thanks
David -
This is interesting - I added a slot for the topLevelChanged() signal:
void topChanged() { qDebug() << "Window flags" << windowFlags(); }
When I undocked the window, it reported:
Window flags QFlags<Qt::WindowType>(Tool|FramelessWindowHint)
and when I docked it, it reported:
Window flags QFlags<Qt::WindowType>(FramelessWindowHint)
that just doesn't seem correct.
The other dock widget in the same application reports much more logical (to me) window flags:
When undocking:
Window flags QFlags<Qt::WindowType>(Tool|WindowTitleHint|CustomizeWindowHint)
when docking:
Window flags QFlags<Qt::WindowType>(FramelessWindowHint)
The main difference I can think of between the two is that the first has a "title bar widget" set on it.
The working build used Qt 6.5.1. The strange thing is that if it build it now the undocked window DOESN'T have a sizing border, even though the distributed version does???
This is Windows 11 BTW
David -
@Axel-Spoerl Any thoughts?
-
Hi David,
that's quite interesting. The dockwidget becomes frameless, if Qt assumes that the window manager will draw native window decoration. It assumes so on Windows and MacOS, as well as Linux, provided that the window system is neither X11, nor wayland.
So you must actually be working on Windows or MacOS, but for some reason the OS won't decorate the floating dock.
I can't reproduce that here. It's either a corner case triggering a bug in Qt, or preventing the window manager from doing its job.
Not sure if this helps you though. -
I've been struggling to reproduce it here - I added a title bar widget to one of the dock widget in the sample, but that behaved as it should...
Strange that rebuilding an already released version of the code results in different behaviour than running the release binary!!?
That's really odd! -
Here's the entire code for the DockWidget in question:
picturelist.h
#pragma once #include "ui/ui_PictureList.h" namespace DSS { class PictureList : public QDockWidget, public Ui::PictureList { friend class StackingDlg; typedef QDockWidget Inherited; Q_OBJECT public: PictureList(QWidget* parent = nullptr); ~PictureList(); private: QLabel* dockTitle; #if QT_VERSION < 0x060601 // Shouldn't need this in QT 6.6.1 inline void setDSSClosing() { dssClosing = true; } protected: void closeEvent(QCloseEvent* event); private: bool dssClosing; #endif }; }
picturelist.cpp
#include "stdafx.h" #include "picturelist.h" namespace DSS { PictureList::PictureList(QWidget* parent) : QDockWidget(parent), dockTitle{ new QLabel(this) } { setupUi(this); tableView->horizontalHeader()->setSortIndicator(1, Qt::AscendingOrder); tableView->horizontalHeader()->setSortIndicatorShown(true); dockTitle->setToolTip(tr("Double click here to dock/undock the image list")); // // Set an informative title bar on the dockable image list with a nice gradient // as the background (like the old "listInfo" static control). // QSize size{ 625, 25 }; dockTitle->setObjectName("dockTitle"); dockTitle->setMinimumSize(size); dockTitle->resize(size); dockTitle->setStyleSheet(QString::fromUtf8("QLabel {" "background: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, " "stop:0 rgba(138, 185, 242, 0), stop:1 rgba(138, 185, 242, 255))}")); setTitleBarWidget(dockTitle); } PictureList::~PictureList() {} #if QT_VERSION < 0x060601 // Shouldn't need this in QT 6.6.1 // // The user may not close the undocked window, but once DSS has set the // closing flag a closeEvent must be accepted (default) otherwise DSS // shutdown never completes. // void PictureList::closeEvent(QCloseEvent* event) { if (!dssClosing) event->ignore(); } #endif }
if I uncomment the setTitleBarWidget(dockTitle); line it works as expected (i.e. the dock widget has sizing borders when undocked), except of course that the title bar isn't set as I want.
D.
-
Hi David,
looking into this. The frame width isn't DPI scaled.
That can be fixed. Need to investigate, why a title bar widget causes the dock widget to be frameless though. -
Hi David,
looking into this. The frame width isn't DPI scaled.
That can be fixed. Need to investigate, why a title bar widget causes the dock widget to be frameless. -
Perhaps you may need to do a SetWindowLongPtr() for the window when you un-dock it, adding the style flag WS_SIZEBOX:
WS_SIZEBOX 0x00040000L The window has a sizing border. Same as the WS_THICKFRAME style.
LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE); style |= WS_SIZEBOX; std::ignore = SetWindowLongPtr(hwnd, GWL_STYLE, style); SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_DRAWFRAME); //show window after updating ShowWindow(hwnd, SW_SHOW);
and turn that flag off when re-docking the window
-
Dock widgets have been handled on a platform abstracted layer. They have a fair share of my love, but not all my time unfortunately. I need to wrap my head around why this is happening.
-
Interesting!
Could you throw aqInfo() << "Application Style:" << QApplication::style();
into the code and see if there's a difference between debug and release mode?