How to made a QDockWidget appears in taskbar?

谁都会走 提交于 2019-12-24 07:00:08

问题


I use a subclass of QDockWidget with a little trick. The "topLevelChanged" signal is connected to this member slot :

void MyDockWidget::updateWindowFlags(bool topLevel)
{
    if (topLevel == true)
    {
        setWindowFlags(Qt::Dialog|Qt::CustomizeWindowHint|Qt::WindowTitleHint|Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint);

        // "setWindowFlags" hides the widget, show it again
        show();
    }
}

This works well (at least on Windows, which is my target) and display a "maximize" button in the title bar.

Now I want to make the dock widget behave like a "top level" widget : not always on top of the main window and appears in taskbar.

I've tried to :

  • reparent the dock widget to NULL when it is detached from main window
  • reparent the dock widget to previous parent when it is re-attached from main window

But there is still some problems : the user can't use drag'n'drop anymore to re-attach the dock to the main window.

I think this is because the parent is NULL, so the dock widget doesn't know where it should re-attach on drag'n'drop.

Is there any way to have the desired behaviour (dock widget not always on top and appears in task bar) without re-parenting it to NULL ? Playing with some flags ?

Or is there anyway to have the dock widget to behave properly when its parent is set to NULL ?

Thanks


回答1:


You can set the windows EX style WS_EX_APPWINDOW:

#ifdef Q_OS_WIN32
#include "qt_windows.h"
#ifdef _MSC_VER
    #pragma comment(lib,"user32.lib")
#endif
// MinGW: add >>LIBS += -lUser32<< to .pro file.
void makeWidgetApearInWindowsTaskbar(QWidget* widget) {
    HWND id = HWND(widget->winId());

    ::ShowWindow(id, SW_HIDE);
    ::SetWindowLong(id, GWL_EXSTYLE, GetWindowLong(id, GWL_EXSTYLE) | WS_EX_APPWINDOW);
    ::ShowWindow(id, SW_SHOW);
}
#endif


来源:https://stackoverflow.com/questions/44707344/how-to-made-a-qdockwidget-appears-in-taskbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!