如何使QDockWidget出现在任务栏中? [英] How to made a QDockWidget appears in taskbar?

查看:257
本文介绍了如何使QDockWidget出现在任务栏中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过一些技巧来使用QDockWidget的子类. "topLevelChanged"信号连接到该成员插槽:

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();
    }
}

这很好(至少在Windows上是我的目标),并且在标题栏中显示最大化"按钮.

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.

我尝试过:

  • 与主窗口分离时,将停靠小部件重新设置为NULL
  • 从主窗口重新附加时,
  • 将停靠小部件与上一个父级相对应
  • 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.

我认为这是因为父级为NULL,所以停靠小部件不知道在拖放时应在何处重新连接.

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.

是否有任何方法可以将期望的行为(dock小部件不总是位于顶部并出现在任务栏中)而无需将其重新设置为NULL?玩一些标志吗?

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 ?

还是当其父项设置为NULL时,是否有必要使Dock小部件正常工作?

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

谢谢

推荐答案

您可以设置Windows EX样式WS_EX_APPWINDOW:

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

这篇关于如何使QDockWidget出现在任务栏中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆