Borders for the QDockWidget 4.8
-
Hello all,
Can someone suggest me, how to set the " Real borders " for the QDockwidget. Usually Dock comes with no border and only with tittle bar. I want to set the "real border" with color, for the Dock I made some search on google , it does not help me.
I am using Qt 4.8.5 on Win10.thanks and regards,
Sumi. -
Hi,
The windows decoration themselves are not handle by Qt but by the current Window Manager you are using. Which is it ?
-
@N.Sumi said:
Usually Dock comes with no border and only with tittle bar.
When dock is detached it is displayed as Tool window (has Qt::Tool window flag). Whether it has a visible border or not depends on the window manager. In Windows 10 tool windows have no visible border except for a shadow you can grab to resize. That's not the case in previous versions of Windows though, which provided a thinner border for tool windows.
I want to set the "real border"
If by "real border" you mean a border used for normal windows (not tool windows), which in Windows 10 is a thin colored line, then you'll have to change windows flags of the dock manually when it is detached from main window. Below is a proof-of-concept quality example of a QDockWidget that does that:
class MyDockWidget : public QDockWidget { public: MyDockWidget(const QString& title, QWidget* parent = nullptr) : QDockWidget(title, parent), detached(false) { connect(this, &MyDockWidget::topLevelChanged, [&](bool topLevel) { detached = topLevel; //can't change flags while window is still dragged so just mark as detached }); } bool event(QEvent* evt) override { if(evt->type() == QEvent::WindowActivate && detached) { detached = false; setWindowFlags(Qt::Window); //adjust flags to add whatever you need e.g. Qt::WindowCloseButtonHint show(); //changing flags hides the window so show it again } return QDockWidget::event(evt); } private: bool detached; };