QT6 源(36):界面组件的总基类 QWidget 的源码阅读(上,属性部分),补充本 QWidget类与QDialog类的信号与槽函数汇总

(1)其源代码定义于文件 qwidget.h 。本结构很长,因为很重要。故拆分成多段。先给出其中的属性部分,注释来自于对官方文档的机翻:

class QWidgetData  //看着像本类 QWidget的数据成员
{
public:
    WId              winid                  ;
    uint             widget_attributes      ;
    Qt::WindowFlags  window_flags           ; //=QFlags<WindowType> 枚举类
    uint             window_state        : 4;
    uint             focus_policy        : 4;
    uint             sizehint_forced     : 1;
    uint             is_closing          : 1;
    uint             in_show             : 1;
    uint             in_set_window_state : 1;
    mutable uint     fstrut_dirty        : 1;
    uint             context_menu_policy : 3;
    uint             window_modality     : 2;
    uint             in_destructor       : 1;
    uint             unused              :13;
    QRect            crect                  ;
    mutable QPalette pal                    ; //Palette 调色板
    QFont            fnt                    ;
    QRect            wrect                  ;
};

class QWidgetPrivate;

//前已阅读了 QPaintDevice,此类没啥内容,只有一些读属性的函数,反馈绘图方面的配置属性
class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice
{
    Q_OBJECT  //宏定义,再次插入此宏

private:
    Q_DISABLE_COPY(QWidget) //禁止对本类的复制

    Q_PRIVATE_SLOT(d_func(), void _q_showIfNotHidden())
    Q_PRIVATE_SLOT(d_func(), QWindow *_q_closestWindowHandle())

    QWidgetData * data; //本类的数据成员

public:
/*
#define Q_DECLARE_PRIVATE(Class) \
    inline Class##Private* d_func() noexcept \
    {   Q_CAST_IGNORE_ALIGN(return reinterpret_cast<  \
            Class##Private *>(qGetPtrHelper(d_ptr));) \
    } \
    inline const Class##Private* d_func() const noexcept \
    {   Q_CAST_IGNORE_ALIGN(return reinterpret_cast< \
        const Class##Private *>(qGetPtrHelper(d_ptr));)  \
    } \
    friend class Class##Private;
*/
    Q_DECLARE_PRIVATE(QWidget) //本宏展开后是为本类增添了成员函数 d_func()

    //此属性表示该小部件是否为模态小部件。默认情况下,此属性为假。
    //这个属性只对窗口有意义。模态小部件会阻止所有其他窗口中的小部件获得任何输入。
    //This property holds whether the widget is a modal widget
    Q_PROPERTY(bool modal READ isModal)

    //This enum specifies the behavior of a modal window.
    //A modal window is one that blocks input to other windows.
    //Note that windows that are children of a modal window are not blocked.
    Q_PROPERTY(Qt::WindowModality windowModality
                   READ windowModality WRITE setWindowModality)
  //Qt::NonModal         0  The window is not modal and
        //does not block input to other windows.
  //Qt::WindowModal      1  The window is modal to a single window hierarchy
        //and blocks input to its parent window, all grandparent windows,
        //and all siblings of its parent and grandparent windows.
  //Qt::ApplicationModal 2  The window is modal to the application and
        //blocks input to all windows.

    //此属性表示小部件是否已启用。-般来说,启用的小部件处理键盘和鼠标事件;禁用的小部件不处理。
    //QAbstractButton是一个例外。一些小部件在禁用时会以不同的方式显示自己。
    //例如,一个按钮可能会将其标签变为灰色。如果你的小部件需要知道何时启用或禁用,
    //你可以使用类型为 QEvent::EnabledChange 的 changeEvent()方法。
    //禁用小部件会隐式地禁用其所有子小部件。启用小部件会分别启用所有子小部件,
    //除非它们已被显式禁用。如果父小部件仍处于禁用状态,则无法显式启用不是窗口的子小部件。
    //This property holds whether the widget is enabled
    //In general an enabled widget handles keyboard and mouse events;
    //a disabled widget does not. An exception is made with QAbstractButton.
    //Some widgets display themselves differently when they are disabled.
    //For example a button might draw its label grayed out.
    //If your widget needs to know when it becomes enabled or disabled,
    //you can use the changeEvent() with type QEvent::EnabledChange.
    //Disabling a widget implicitly disables all its children.
    //Enabling respectively enables all child widgets unless
    //they have been explicitly disabled.
    //It it not possible to explicitly enable a child widget
    //which is not a window while its parent widget remains disabled.
    Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)//默认情况下,此属性为真。


    //此属性包含小部件相对于其父级(不包括窗口框架)的几何形状。当更改几何形状时,如果小部件可见,
    //它将立即接收移动事件(moveEvent())和/或调整大小事件(resizeEvent())。
    //如果小部件当前不可见,则在显示之前肯定会接收适当的事件。
    //如果大小组件位于由minimumSize()和maximumSize()定义的范围之外,则会调整大小组件。
    //警告:在resizeEvent()或moveEvent()中调用setGeometry()可能会导致无限递归。
    //请参阅“窗口几何”文档,以了解有关窗口几何问题的概述。
    //默认情况下,此属性包含一个值,该值取决于用户的平台和屏幕几何。
    //This property holds the geometry of the widget relative to its parent and
//excluding the window frame When changing the geometry, the widget, if visible,
//receives a move event (moveEvent()) and/or a resize event (resizeEvent())
//immediately. If the widget is not currently visible,
//it is guaranteed to receive appropriate events before it is shown.
//The size component is adjusted if it lies outside the range
//defined by minimumSize() and maximumSize().
//Warning: Calling setGeometry() inside resizeEvent() or moveEvent()
//can lead to infinite recursion.
//See the Window Geometry documentation for an overview of geometry issues
//with windows. By default, this property contains a value
//that depends on the user's platform and screen geometry.
    Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry)
    //取值是个数组 [ x , y, width, height ]

    //geometry of the widget relative to its parent including any window frame
    Q_PROPERTY(QRect frameGeometry READ frameGeometry) //此属性不可见

    //此属性包含小部件的几何形状,当显示为正常(未最大化或全屏)顶层小部件时,它将显示该几何形犬
    //如果小部件已经处于这种状态,则正常几何将反映小部件的当前几何。对于子控件,
    //此属性始终包含一个空矩形。默认情况下,此属性包含一个空矩形。
    //This property holds the geometry of the widget as it will appear
    //when shown as a normal (not maximized or full screen) top-level widget。
    //If the widget is already in this state ,
    //the normal geometry will reflect the widget's current geometry().
    //For child widgets this property always holds an empty rectangle.
    //By default, this property contains an empty rectangle.
    Q_PROPERTY(QRect normalGeometry READ normalGeometry)

    //This property holds the x coordinate of the widget relative to its parent
    //including any window frame。By default, this property has a value of 0.
    Q_PROPERTY(int x READ x)

    Q_PROPERTY(int y READ y)

    //此属性包含小部件的宽度,
    //注意:不要使用此函数在多屏幕桌面上查找屏幕宽度。请参QScreen以获取详细信息。
    //This property holds the width of the widget excluding any window frame。
    //Note: Do not use this function to find the width of a screen on a
    //multi-screen desktop. See QScreen for details.
    Q_PROPERTY(int width READ width)

    //This property holds the height of the widget excluding any window frame
    Q_PROPERTY(int height READ height)

    //This property holds the widget's minimum width in pixels。
    //This property corresponds to the width held by the minimumSize property.
    //By default, this property has a value of 0.
    Q_PROPERTY(int minimumWidth  READ minimumWidth  WRITE setMinimumWidth
                   STORED false  DESIGNABLE false) //不可见

    //This property holds the widget's minimum height in pixels。
    //By default, this property has a value of 0.
    Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight
                   STORED false  DESIGNABLE false)

    //This property holds the widget's maximum width in pixels
    //This property corresponds to the width held by the maximumSize property.
    //By default, this property contains a value of 16777215.
    //Note: The definition of the QWIDGETSIZE_MAX macro limits
    //the maximum size of widgets.
    Q_PROPERTY(int maximumWidth  READ maximumWidth  WRITE setMaximumWidth
                   STORED false  DESIGNABLE false)  //不可见

    Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight
                   STORED false  DESIGNABLE false)

    //This property holds the internal geometry of the widget
    //excluding any window frame。
    //The rect property equals QRect(0, 0, width(), height()).
    Q_PROPERTY(QRect rect READ rect) // QRect rect() const

    //This property holds the bounding rectangle of the widget's children
    //Hidden children are excluded. By default, for a widget with no children,
    //this property contains a rectangle with zero width and height
    //located at the origin.
    Q_PROPERTY(QRect childrenRect READ childrenRect)

    //这个属性持有由小部件的子元素占据的合并区域
    //This property holds the combined region occupied by the widget's children
    //Hidden children are excluded. By default, for a widget with no children,
    //this property contains an empty region.
    Q_PROPERTY(QRegion childrenRegion READ childrenRegion)

    //This property holds the position of the widget within its parent widget
    //If the widget is a window, the position is that of the widget on the desktop,
    //including its frame. When changing the position, the widget, if visible,
    //receives a move event (moveEvent()) immediately.
    //If the widget is not currently visible,
    //it is guaranteed to receive an event before it is shown.  //此属性不可见的
    //By default, this property contains a position that refers to the origin.
    Q_PROPERTY(QPoint pos READ pos WRITE move DESIGNABLE false STORED false)

    //This property holds the size of the widget including any window frame。
    //By default, this property contains a value
    //that depends on the user's platform and screen geometry。
    Q_PROPERTY(QSize frameSize READ frameSize)

    //This property holds the size of the widget excluding any window frame。
    //Note: Setting the size to QSize(0, 0) will  //本属性依然不可见
    //cause the widget to not appear on screen. This also applies to windows.
    Q_PROPERTY(QSize size READ size WRITE resize DESIGNABLE false STORED false)

    //此属性持有小部件的默认布局行为。如果存在一个QLayout来管理此小部件的子元素,
    //则使用该布局指定的大小策略。如果没有这样的QLayout则使用此函数的返回值。
    //默认策路是Preferred/Preferred,这意味着小部件可以自由调整大小,
    //但倾向于返回sizeHint()返回的大小。类似按钮的小部件将设置大小策略,以指定它们可以水平拉伸,
    //但垂直固定,这同样适用于lineedit控件(如OLineEdit、OSpinBox或可编辑的OComboBox)和
    //其他水平排列的小部件(如QProgressBar)。QToolButton通常是正方形的,
    //因此它们允许双向生长支持不同方向的小部件(如OSlider、OScrollBar或OHeader)仅指定
    //在相应方向上的拉伸。可以提供滚动条的小部件(通常是 QScrollArea的子类)倾向于
    //指定它们可以使用额外的空间并且它们可以使用小于 sizeHint()的空间。
    //This property holds the default layout behavior of the widget。
    //If there is a QLayout that manages this widget's children,
    //the size policy specified by that layout is used.
    //If there is no such QLayout, the result of this function is used.
    //The default policy is Preferred/Preferred,
    //which means that the widget can be freely resized,
    //but prefers to be the size sizeHint() returns.
    //Button-like widgets set the size policy to specify that
    //they may stretch horizontally, but are fixed vertically.
    //The same applies to lineedit controls (such as QLineEdit, QSpinBox or
    //an editable QComboBox) and other horizontally orientated widgets
    //(such as QProgressBar). QToolButton's are normally square,
    //so they allow growth in both directions.
    //Widgets that support different directions (such as QSlider,
    //QScrollBar or QHeader) specify stretching in the respective direction only.
    //Widgets that can provide scroll bars (usually subclasses of QScrollArea)
    //tend to specify that they can use additional space,
    //and that they can make do with less than sizeHint().
    Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)

    //This property holds the widget's minimum size。
    //The widget cannot be resized to a smaller size than the minimum widget size.
    //The widget's size is forced to the minimum size if the current size
    //is smaller. The minimum size set by this function will override
    //the minimum size defined by QLayout. In order to unset the minimum size,
    //use a value of QSize(0, 0).
    //By default, this property contains a size with zero width and height.
    Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)

    //This property holds the widget's maximum size in pixels。
    //The widget cannot be resized to a larger size than the maximum widget size.
    //By default, this property contains a size in which
    //both width and height have values of 16777215.
//Note: The definition of the QWIDGETSIZE_MAX macro limits
    //the maximum size of widgets.
    Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)

    //这个属性持有小部件的尺寸增量。当用户调整窗口大小时,大小将以
    //sizelncrement().width()像素的水平增量和sizelncrement()height()像素的垂直增量移动,
    //以 baseSize()为基础。首选小部件大小是非负整数i和 j。
    //请注意,虽然您可以设置所有小部件的大小增量,但它只影响窗口。
    //默认情况下,此属性包含宽度为0、高度为0的尺寸。
    //警告:在 Windows 下,大小增量没有影响,X11的窗口管理器可能会忽略它。
    //机器翻译时,总把 Widget 翻译成小部件,把  window 翻译成窗口。这可能不大准确。
    Q_PROPERTY(QSize sizeIncrement READ sizeIncrement WRITE setSizeIncrement)

    //This property holds the base size of the widget
    //The base size is used to calculate a proper widget size
    //if the widget defines sizeIncrement().
    //By default, for a newly-created widget,
    //this property contains a size with zero width and height.
    Q_PROPERTY(QSize baseSize READ baseSize WRITE setBaseSize)

    //This property holds whether this widget is minimized (iconified)
    //This property is only relevant for windows.
    //By default, this property is false.
    Q_PROPERTY(bool minimized READ isMinimized) //本窗口是否被最小化了,看其读函数

    //注:由于某些窗口系统的限制,这并不总是报告预期结果
    //(例如,如果X11上的用户通过窗口管理器最大化窗口,Qt没有区分这一点与其他任何调整大小的方法)。
    //随着窗口管理器协议的演变,预计这种情况会有所改善。
    //This property holds whether this widget is maximized
    //This property is only relevant for windows.
    //By default, this property is false.
    Q_PROPERTY(bool maximized READ isMaximized)

    //This property holds whether the widget is shown in full screen mode
    //A widget in full screen mode occupies the whole screen area and
    //does not display window decorations, such as a title bar.
    //By default, this property is false.
    Q_PROPERTY(bool fullScreen READ isFullScreen) //这不是一个可显示的属性

    //This property holds the recommended size for the widget
    //If the value of this property is an invalid size, no size is recommended.
    //The default implementation of sizeHint() returns an invalid size
    //if there is no layout for this widget,
    //and returns the layout's preferred size otherwise.
    Q_PROPERTY(QSize sizeHint READ sizeHint)  //提示Hint。
    //class QSize { int wd; int ht;} 这是其简化定义

    //这个属性持有小部件的推荐最小尺寸
    //如果此属性的值是无效的大小,则不建议最小大小。
    //如果此小部件没有布局,则minimumSizeHint()的默认实现将返回无效的大小,
    //否则将返回布局的最小大小。大多数内置小部件都会重新实现minimumSizeHint()
    //OLavout永远不会将小部件的尺寸缩小到小于最小尺寸提示的尺寸,
    //除非设置了最小尺寸提示或设置了大小策略为QSizePolicy::gnore。
    //If minimumSize() is set, the minimum size hint will be ignored.
    Q_PROPERTY(QSize minimumSizeHint READ minimumSizeHint)

    //此属性持有小部件的调色板
    //这个属性描述了小部件的调色板。在渲染标准组件时,调色板由小部件的样式使用,
//并且可以作为确保自定义小部件与本地平台的外观和感觉保持一致的一种手段。
//不同的平台或不同的样式通常有不同的调色板。当你将一个新的调色板分配给一个widget时,
//这个调色板中的颜色角色会与widget的默认调色板结合,形成widget的最终调色板。
//widget背景角色的调色板条目用于填充widget的背景(参见QWidget:.autoFillBackground),
//而前景角色初始化QPainter的笔。默认值取决于系统环境。`QApplication`维护一个系统/主题调色板,
//作为所有小部件的默认值。对于某些类型的小部件,可能还有特殊的调色板默认值
//(例如,在WindowsVista上,所有从`QMenuBar`派生的类都有一个特殊的默认调色板)。
//您还可以通过传递自定义调色板和一个小部件的名称来定义小部件的默认调色板。
//最后,样式始终可以选择在分配调色板时对其进行润色(参见`QStyle::polish()')。
//QWidget 会将显式的调色板角色从父对象传播到子对象。如果您将画笔或颜色分配给调色板上的特定角色,
//并将该调色板分配给一个控件,则该角色将传播到该控件的所有子控件,覆盖该角色的任何系统默认值。
//请注意,默认情况下,调色板不会传播到窗口(请参阅isWindow()),
    //除非启用了 Qt::WA_WindowPropagation 属性。
    //QWidget的调色板传播类似于其字体传播。
    //当前样式用于呈现所有标准 Qt 窗口部件的内容,可以自由选择窗口部件调色板中的颜色和刷子,
    //或者在某些情况下忽略调色板(部分或完全忽略)。特别是,
    //某些样式(如 GTK样式、Mac样式和 Windows Vista样式)依赖于第三方 APs来呈现窗口部件的内容,
    //这些样式通常不遵循调色板。因此,将角色分配给窗口部件的调色板并不能保证改变窗口部件的外观。
    //相反,您可以选择应用样式表。
//Warning: Do not use this function in conjunction with Qt Style Sheets.
//When using style sheets, the palette of a widget can be customized定制 using the
//"color", "background-color", "selection-color", "selection-background-color"
    //and "alternate-background-color".
    Q_PROPERTY(QPalette palette READ palette WRITE setPalette)

    //这个属性持有当前为该小部件设置的字体这个属性描述了小部件请求的字体。当渲染标准组件时,
  //字体由小部件的样式使用,并且可以作为确保自定义小部件与本地平台的外观和感觉保持一致的一种手段。
    //不同平台或不同样式为应用程序定义不同的字体是很常见的。
    //当您将新字体分配给小部件时,此字体的属性将与小部件的默认字体结合,形成小部件的最终字体。
    //您可以通过调用fontnfo()来获取小部件最终字体的副本。最终字体也用于初始化QPainter的字体。
    //默认值取决于系统环境。QApplication维护一个系统/主题字体,作为所有小部件的默认值。
    //对于某些类型的小部件,可能还有特殊的字体默认值。您还可以通过传递自定义字体和
    //一个小部件的名称给2Application:setFont()来自己定义小部件的默认字体。
    //最后,该字体与Qt的字体数据库进行匹配以找到最佳匹配。
    //QWidget 会将显式的字体属性从父级传递到子级。如果您更改字体上的特定属性并将其分配给
    //一个widget,则该属性将传递到widget的所有子级,覆盖该属性的任何系统默认值。
    //请注意,默认情况下,字体不会传递到窗口(请参阅isWindow()),
    //除非启用了Qt:WA_WindowPropagation属性。QWidget的字体传播类似于其调色板传播。
    //当前样式用于呈现所有标准 Qt窗口小部件的内容,可以自由选择使用窗口小部件字体,
    //或者在某些情况下忽略它(部分或完全忽略)。特别是,某些样式(如 GTK样式、Mac 样式和
    //Windows Vista 样式)会对窗口小部件字体进行特殊修改,以匹配平台的本地外观和感觉。
    //因此,将属性分配给窗口小部件的字体并不能保证改变窗口小部件的外观。
    //相反,您可以选择应用样式表。
    //Note: If Qt Style Sheets are used on the same widget as setFont(),
    //style sheets will take precedence if the settings conflict.
    Q_PROPERTY(QFont font READ font WRITE setFont)

#ifndef QT_NO_CURSOR
    //此属性持有此小部件的游标形状。当鼠标光标悬停在这个小部件上时,它将呈现这种形状。
    //查看预定义光标对象列表,以获取一系列有用的形状。// setCursor(Qt::IBeamCursor);
    //如果没有设置光标,或者在调用unsetCursor()之后,将使用父窗口的光标。
    //默认情况下,此属性包含一个形状为 Qt::ArrowCursor 的光标。
    //如果鼠标被抓住,一些底层窗口实现会在光标离开小部件时重置光标,即使鼠标被抓住。
    //如果你想为所有小部件设置光标,即使在小部件之外,
    //请考虑使用0GuiApplication::setOverrideCursor()
    Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)
#endif

    //这个属性表示是否为该小部件启用了鼠标跟踪。 如果禁用鼠标跟踪(默认情况),
    //则在移动鼠标时按下至少一个鼠标按钮时,小部件仅接收鼠标移动事件。
    //如果启用了鼠标跟踪,即使没有按下按钮,小部件也会接收鼠标移动事件。
    Q_PROPERTY(bool mouseTracking READ hasMouseTracking WRITE setMouseTracking)

    //此属性表示是否启用了小部件的平板电脑跟踪功能。如果禁用平板电脑跟踪(默认设置),
    //则小部件仅在笔与平板电脑接触时或在笔移动时按下至少一个笔按钮时接收平板电脑移动事件。
    //如果启用了平板电脑跟踪,即使在接近时悬停,小部件也会接收平板电脑移动事件。
    //这有助于监控位置以及旋转和倾斜等辅助属性,并在用户界面中提供反馈。
    Q_PROPERTY(bool tabletTracking READ hasTabletTracking WRITE setTabletTracking)

    //此属性表示此小部件的窗口是否为活动窗口。活动窗口是包含具有键盘焦点的控件的窗口
    //(如果该窗口没有控件或没有控件接受键盘焦点,则该窗口可能仍然具有焦点)。
    //当弹出窗口可见时,对于活动窗口和弹出窗口,此属性都为真。默认情况下,此属性为假。
    Q_PROPERTY(bool isActiveWindow READ isActiveWindow)

    //这个枚举类型定义了小部件在获取键盘焦点方面可以具有的各种策略。关于Qt::FocusPolicy
    Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
    //关于Qt::FocusPolicy 中枚举量的注释见另一个头文件

    //This property holds whether this widget (or its focus proxy)
    //has the keyboard input focus。 By default, this property is false.
    //注:为控件获取此属性的值实际上等同于检查 QApplication::focusWidget()是否指定了该控件。
    Q_PROPERTY(bool focus READ hasFocus)

    //这个枚举类型定义了小部件在显示上下文菜单方面可以具有的各种策略。关于枚举量的注释见另文
    Q_PROPERTY(Qt::ContextMenuPolicy contextMenuPolicy
                   READ contextMenuPolicy WRITE setContextMenuPolicy)

    //此属性表示是否启用了更新。-个启用更新的小部件会接收绘制事件并具有系统背景;禁用的小部件则没有。
    //这也意味着,如果更新被禁用,调用update()和repaint()没有任何效果。默认情况下,此属性为真。
    //setUpdatesEnabled()通常用于在短时间内禁用更新,例如避免在发生大变化时屏幕闪烁。
    //在 Qt中,小部件通常不会产生屏幕闪烁,但在X11上,当小部件被其他小部件替换之前被隐藏时,
    //服务器可能会擦除屏幕上的区域。禁用更新可以解决这个问题。
    Q_PROPERTY(bool updatesEnabled
                   READ updatesEnabled WRITE setUpdatesEnabled DESIGNABLE false)


    //此属性表示小部件是否可见。
//调用 setVisible(true)或show()会将小部件设置为可见状态,如果其所有父小部件(直到窗口)都是可见的。
    //如果祖先不可见,则小部件不会变得可见,直到所有祖先都显示出来。
    //如果小部件的大小或位置已更改,Qt保证在显示小部件之前会收到移动和重绘事件。
    //如果小部件尚未重新调整大小,Ot将使用adiustSize()方法将小部件的大小调整到有用的默认值
    //调用 setVisible(false)或 hide()会显式隐藏一个小部件。
    //显式隐藏的小部件永远不会变得可见,即使其所有祖先都变得可见,除非您显示它。
    //当小部件的可见性状态改变时,它会接收显示和隐藏事件。
    //在隐藏和显示事件之间,不需要浪费CPU周期来准备或向用户显示信息。
    //例如,视频应用程序可以简单地停止生成新帧。
    //同样适用于图标化窗口和存-个碰巧被屏幕上的其他窗口遮挡的小部件被认为是可见的。
    //在于另一个虚拟桌面上的窗口(在支持这个概念的平台中)。
    //当窗口系统改变小部件的映射状态时,小部件会接收自发的显示和隐藏事件,
    //例如,当用户最小化窗口时发生自发的隐藏事件,当窗口恢复时发生自发的显示事件。
    //你几乎永远不需要重新实现setVisible()函数。
    //如果你需要在显示小部件之前更改一些设置,请使用showEvent()函数。
    //如果你需要执行一些延迟初始化,请使用传递给event()函数的波兰事件。Polish event
    Q_PROPERTY(bool visible READ isVisible WRITE setVisible DESIGNABLE false)

    //此属性表示是否启用此小部件的删除事件。
    //将此属性设置为 true 可以向系统宣布此小部件可能能够接受拖放事件。
//如果小部件是桌面(windowType()==Qt::Desktop),如果另一个应用程序正在使用桌面,则可能失败;
    //您可以调用acceptDrops()来测试是否发生这种情况。
    //默认情况下,此属性为假。   !警告:不要在拖放事件处理程序中修改此属性。
    Q_PROPERTY(bool acceptDrops READ acceptDrops WRITE setAcceptDrops)

    //此属性包含窗口标题(标题)。这个属性只适用于顶级小部件,如窗口和对话框。
//如果没有设置标题,则标题基于windowFilePath如果这两个都没有设置,则标题为空字符串。
//如果你使用windowModified机制,窗口标题必须包含一个“【*】”占位符,它指示 '*' 应该出现的位置。
    //通常,它应该在文件名之后出现(例如,“document1.txt*-文本编辑器”)。
    //如果windowModified属性为false(默认值),则仅删除占位符。
//On some desktop platforms (including Windows and Unix), the application name
//(from QGuiApplication::applicationDisplayName) is added at the end of
    //the window title, if set.
    //这是由QPA插件完成的,因此会显示给用户但并不是窗口标题字符串的一部分。
    Q_PROPERTY(QString windowTitle
        READ windowTitle WRITE setWindowTitle NOTIFY windowTitleChanged)

    //此属性包含小部件的图标. 这个属性只对窗口有意义。
    //This property only makes sense for windows.
    //If no icon has been set, windowIcon() returns the application icon
    //(QApplication::windowIcon()).
    //Note: On macOS, window icons represent the active document,
    //and will not be displayed unless a file path has also been set
    //using setWindowFilePath.
    Q_PROPERTY(QIcon windowIcon
        READ windowIcon WRITE setWindowIcon NOTIFY windowIconChanged)

    //这个属性已被弃用。我们强烈建议在新代码中不要使用它。
    Q_PROPERTY(QString windowIconText  // deprecated
        READ windowIconText WRITE setWindowIconText NOTIFY windowIconTextChanged)

    //此属性包含窗口的透明度级别。不透明度有效的范围是从1.0(完全不透明)到0.0(完全透明)
    //默认情况下,此属性的值为 1.0。 此功能在支持Composite扩展的嵌入式Linux、macOS、
    //Windows和X11平台上可用。
    //警告:将这种属性从不透明改为透明可能会引发一个需要在窗口正确显示之前处理的绘制事件。
    //这主要影响 QScreen:grabWindow()的使用。
    //另外请注意,半透明窗口的更新和大小调整比不透明窗口慢得多。
    Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity)

    //这个属性表示窗口中显示的文档是否有未保存的更改。
    //修改过的窗口是指其内容已更改但未保存到磁盘上的窗口。此标志在不同平台上具有不同的效果。
    //在macOS上,关闭按钮将具有修改过的外观;在其他平台上,窗口标题将带有“*”(星号)。
    //窗口标题必须包含一个“【*】”占位符,它指示“*”应出现的位置。通常,它应该在文件名之后出现
    //(例如,“document1.txt【*】-文本编辑器”)。如果未修改窗口,则仅删除占位符。
    //请注意,如果将一个小部件设置为已修改,则其所有祖先也将设置为已修改。
    //但是,如果您在小部件上调用setWindowModified(false),则不会将其传播到父级,
    //因为父级的其他子项可能已经修改
    Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified)

#if QT_CONFIG(tooltip) //经测试为true ,if 有效
    //此属性包含小部件的提示信息。请注意,默认情况下,工具提示仅对作为活动窗口的子窗口小部件显示。
    //您可以通过在窗口上设置属性 Qt::WA_AlwaysShowToolTips来更改此行为,
    //而不是在带有工具提示的小部件上设置。
    //如果你想控制工具提示的行为,你可以拦截事件()函数并捕获OEvent::ToolTip事件
    //(例如,如果你想自定义应该显示工具提示的区域)。默认情况下,此属性包含一个空字符串。
    Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip)

    //此属性包含小部件的提示持续时间。指定工具提示将显示多长时间,以毫秒为单位。
    //如果值为-1(默认值),则持续时间将根据工具提示的长度计算。
    Q_PROPERTY(int toolTipDuration READ toolTipDuration WRITE setToolTipDuration)
#endif

#if QT_CONFIG(statustip)  //经测试为true ,if 有效
    //This property holds the widget's status tip。
    //By default, this property contains an empty string.
    Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip)
#endif

#if QT_CONFIG(whatsthis) //经测试为true ,if 有效
    //This property holds the widget's What's This help text.
    //By default, this property contains an empty string.
    Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis)
#endif

#ifndef QT_NO_ACCESSIBILITY  //经测试为true ,if 有效
    //此属性包含辅助技术所见的控件名称。这是辅助技术(如屏幕阅读器)宣布此小部件的主要名称。
    //对于大多数小部件,设置此属性是不必要的。例如,对于OPushButton,将使用按钮的文本。
    //当小部件不提供任何文本时,设置此属性非常重要。例如,仅包含图标按钮需要设置此属性才能与
    //屏幕阅读器配合使用。名称应简短,相当于小部件传达的视觉信息。
    //这个属性必须本地化。默认情况下,此属性包含一个空字符串。
    Q_PROPERTY(QString accessibleName
                   READ accessibleName WRITE setAccessibleName)

    //此属性包含辅助技术所见的控件描述。可访问的描述应传达小部件的功能。
    //虽然 accessibleName 应是一个简短而简洁的字符串(例如“保存”),
    //但本描述应提供更多上下文,例如“保存当前文档”。    这个属性必须本地化。
    //默认情况下,此属性包含一个空字符串,Qt 会退回到使用工具提示提供此信息。
    Q_PROPERTY(QString accessibleDescription
                   READ accessibleDescription WRITE setAccessibleDescription)
#endif

    //Specifies the direction of Qt's layouts and text handling.
    //右对齐布局对于某些语言是必要的,特别是阿拉伯语和希伯来语。
    //LayoutDirectionAuto有两个目的。当与widget和布局一起使用时,
    //它将暗示使用父widget或QApplication上设置的布局方向。
    //这具有与QWidget::unsetLayoutDirection()相同的效果。
    //当使用`LayoutDirectionAuto`与文本布局相结合时,
    //它将意味着文本方向性是由要布局的字符串的内容确定的。
    Q_PROPERTY(Qt::LayoutDirection layoutDirection
                READ  layoutDirection
                WRITE setLayoutDirection
                RESET unsetLayoutDirection)

//Window flags are a combination of a type (e.g. Qt::Dialog) and zero or
//more hints to the window system (e.g. Qt::FramelessWindowHint).
//If the widget had type Qt::Widget or Qt::SubWindow and becomes a window
//(Qt::Window, Qt::Dialog, etc.), it is put at position (0, 0) on the desktop.
//If the widget is a window and becomes a Qt::Widget or Qt::SubWindow,
//it is put at position (0, 0) relative to its parent widget.
//Note: This function calls setParent() when changing the flags for a window,
//causing the widget to be hidden.
//You must call show() to make the widget visible again..
    QDOC_PROPERTY(Qt::WindowFlags windowFlags
                READ windowFlags WRITE setWindowFlags)

    //此属性表示是否自动填充小部件背景.
    //如果启用,此属性将导致 Qt在调用 paint 事件之前填充小部件的背景。
    //使用的颜色由小部件调色板中的OPalette::Window颜色角色定义。
    //此外,除非设置了 WA OpaquePaintEvent或WA NoSystemBackground 属性,
    //否则Windows 总是包含 OPalette::Window。
    //如果小部件的父级具有静态渐变背景,则此属性无法关闭(即设置为false)
    //警告:在使用 Ot样式表时,请谨慎使用此属性。
    //当小部件具有具有有效背景或边框图像的样式表时,此属性将自动禁用。
    Q_PROPERTY(bool autoFillBackground  //默认情况下,此属性为假。
                READ autoFillBackground WRITE setAutoFillBackground)

#ifndef QT_NO_STYLE_STYLESHEET
    //此属性包含小部件的样式表.
    //样式表包含对widget样式自定义的文本描述,如Qt样式表文档中所述。
    //自Qt 4.5以来,Qt样式表完全支持macOs。
    //警告:目前不支持自定义 QStyle 子类使用 Qt 样式表。我们计划在未来的某个版本中解决这个问题。
    Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
#endif

    //这个属性持有小部件的本地语言。
    //只要没有设置特殊的区域,这要么是父区域的区域,或者(如果此小部件是顶级小部件),则是默认区域。
    //如果小部件显示日期或数字,则应使用小部件的本地格式化。
    Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET unsetLocale)

    //这个属性持有与一个小部件关联的文件路径。
    //文个属性仅适用于窗口。它将文件路径与窗口关联。
    //如果您设置了文件路径,但未设置窗口标题,则Qt会将窗口标题设置为指定路径的文件名,
    //该文件名使用QFilelnfo:fileName()获取。
    //如果窗口标题在任何时候被设置,那么窗口标题将具有优先权,并且将显示而不是文件路径字符串。
    //此外,在macOS上,这还有一个额外的好处,即它会设置窗口的代理图标,假设文件路径存在。
    //如果没有设置文件路径,此属性包含一个空字符串。
    //默认情况下,此属性包含一个空字符串。
    Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath)

    //该小部件具有的特定提示输入方法。
    //这仅适用于输入小部件。输入法使用它来检索有关输入法应如何操作的提示。
    //例如,如果启用了Qt::lmhFormattedNumbersOnly标志,则输入法可能会更改其视觉组件,
    //以反映只能输入数字。
    //警告:某些小部件需要特定的标志才能按预期工作。
    //Warning: Some widgets require certain flags in order to work as intended.
    //To set a flag, do w->setInputMethodHints( w->inputMethodHints() | f )
    //       instead of w->setInputMethodHints(f).
    //如果您想确保输入了某种类型的字符,还应在小部件上设置 OValidator。
    Q_PROPERTY(Qt::InputMethodHints inputMethodHints //默认值为 Ot::lmhNone。
                READ inputMethodHints WRITE setInputMethodHints) //此枚举值见另文

public:  //以下是  c++ 的正常代码,不再有 

(2) 这俩窗口容器预定义的信号与槽函数汇总

在这里插入图片描述

++给出对应图片的源代码形式

// 这俩窗口容器预定义的信号与槽函数汇总
class QWidget : public QObject, public QPaintDevice
{
Q_SIGNALS:
    void customContextMenuRequested(const QPoint & pos);
    void windowTitleChanged   (const  QString & title);
    void windowIconChanged    (const  QIcon   & icon);
    void windowIconTextChanged(const QString & iconText);

protected Q_SLOTS:
    void updateMicroFocus(Qt::InputMethodQuery query = Qt::ImQueryAll);

public Q_SLOTS:
    void setWindowTitle(const QString &);
    void setWindowModified(bool);
    void setStyleSheet(const QString& styleSheet);
    void setEnabled(bool);
    void setDisabled(bool);
    inline  void setFocus() { setFocus(Qt::OtherFocusReason); }
    void setHidden(bool hidden);
    virtual void setVisible(bool visible);

    void showMinimized();
    void showMaximized();
    void showFullScreen();
    void showNormal();

    void show ();
    void hide ();
    bool close();
    void raise();
    void lower();
    void update ();
    void repaint();
};

class QDialog : public QWidget
{
Q_SIGNALS:
    void finished(int result);
    void accepted();
    void rejected();

public Q_SLOTS:
    virtual void accept();
    virtual void reject();
    virtual void open();
    virtual int  exec();
    virtual void done(int);
}; //为本对话框预定义好的槽函数

(3)

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值