• Qt 单击任务栏图标实现最小化


    Qt中对于窗口边框的设置一般用到setWindowFlags函数。

    void setWindowFlags(Qt::WindowFlags type)
    如果只setWindowFlags(Qt::FramelessWindowHint);
    去掉边框,此时会发现,当程序打开后,单击任务栏的按钮,会发现无法最小化,隐藏窗口。
    解决的方法是:
    setWindowFlags(Qt::Window|Qt::FramelessWindowHint |Qt::WindowSystemMenuHint|Qt::WindowMinimizeButtonHint|Qt::WindowMaximizeButtonHint);
    再次测试,发现边框去掉了,而且鼠标点击任务栏图标,也可以显示和隐藏窗口了。
     
    附:
    Qt::Widget

    This is the default type for QWidget.

    Widgets of this type are child widgets if they have a parent,and independent(独立的) windows if they have no parent.

    See also Qt::Window and Qt::SubWindow.

    Qt::Window

    Indicates(标志,象征) that the widget is a window.

    Usually with a window system frame and a title bar,irrespective of (不管)whether the widget has a parent or not.

    Note that it is not possible to unset this flag if the widget does not have a parent.

    Qt::Dialog Indicates that the widget is a window that should be decorated as a dialog (i.e., typically no maximize or minimize buttons in the title bar). This is the default type for QDialog. If you want to use it as a modal dialog, it should be launched from another window, or have a parent and used with the QWidget::windowModality property. If you make it modal, the dialog will prevent other top-level windows in the application from getting any input. We refer to a top-level window that has a parent as a secondary window.
    Qt::FramelessWindowHint

    Produces a borderless window.

    The user cannot move or resize a borderless window via the window system.

    On X11, the result of the flag is dependent on the window manager and its ability to understand Motif and/or NETWM hints. Most existing modern window managers can handle this.

    Qt::CustomizeWindowHint Turns off the default window title hints.
    Qt::WindowTitleHint Gives the window a title bar.
    Qt::WindowSystemMenuHint

    Adds a window system menu, and possibly a close button (for example on Mac).

     If you need to hide or show a close button, it is more portable to use WindowCloseButtonHint.

    Qt::WindowMinimizeButtonHint

    Adds a minimize button.

    On some platforms this implies Qt::WindowSystemMenuHint for it to work.

    Qt::WindowMaximizeButtonHint

    Adds a maximize button.

    On some platforms this implies Qt::WindowSystemMenuHint for it to work.

    Qt::WindowMinMaxButtonsHint

    Adds a minimize and a maximize button.

    On some platforms this implies Qt::WindowSystemMenuHint for it to work.

    Qt::WindowCloseButtonHint

    Adds a close button.

     On some platforms this implies Qt::WindowSystemMenuHint for it to work.

     
     
  • 相关阅读:
    LeetCode 127. Word Ladder 单词接龙(C++/Java)
    LeetCode 681. Next Closest Time 最近时刻 / LintCode 862. 下一个最近的时间 (C++/Java)
    LeetCode 682. Baseball Game 棒球比赛(C++/Java)
    LeetCode 218. The Skyline Problem 天际线问题(C++/Java)
    小数据池,编码
    字典
    列表
    常见的数据类型
    while循环
    初始python
  • 原文地址:https://www.cnblogs.com/granx/p/9563315.html
Copyright © 2020-2023  润新知