当前位置:网站首页>QT knowledge: QT widgets widget class [01]
QT knowledge: QT widgets widget class [01]
2022-06-12 20:04:00 【Mr anhydrous】
One 、 summary
because QWidget Class itself contains attributes 、 Many methods , And we often use this class , So I'm going to open a series to introduce this class a little .
1、QWidget Is the most basic interface
Its basic function is :
- Receive the mouse from the window system 、 Keyboard and other events ,
- Draw your own representation on the screen .
- The basic shapes are rectangular , They press Z Order .
- A widget is clipped by its parent widget and the widget before it .
2、 Widget without parent window QWidget It's called a window . General properties :
- Windows have borders
- The title bar
- Geometry
3、QWidget Some properties of are not used directly , But it can be implemented in its inherited descendants .
for example ,QWidget There is a font attribute , But never use it . Instead, it is used by its subclasses .
4、 When implementing a new widget , Overload the following functions :
- sizeHint() Provide a reasonable default size for widgets .
- Use setSizePolicy() It is useful to set the correct size policy .
- The size policy provides a good default behavior for the layout management system .
- The default size policy indicates size The prompt indicates the preferred size of the widget .
5、 Widgets respond to events that are usually caused by user actions .
Qt By using... That contains information about each event QEvent Subclass instances call specific event handlers , Pass events to the widget to be handled by the widget .
6、QWidget Use double buffering to draw , So there's no need to be in paintEvent() Write double buffered code to avoid flickering .
Two 、 Enum type members
Today is about QWidget Class has a unique enumeration value RenderFlag. At the end of the article, the matching method will be introduced :
- QWidget::render() Method to render the widget QWidget
- QWidget::setMask() Method .
DrawWindowBackground: If this option is enabled , Even if... Is not set autoFillBackground, The background of the widget is also rendered to the target . By default , This option is enabled .
DrawChildren: If this option is enabled , Then the widget QWidget The children of will be rendered recursively into the target . By default , This option is enabled .
IgnoreMask: If this option is enabled , The widget's... Will be ignored when rendered to the target QWidget::mask(). By default , This option is disabled .
3、 ... and 、 Static attribute members
1、acceptDrops : bool -- Accept drag and drop Events . The default is false.
2、accessibleDescription : QString -- Description of the widget . The description should provide relatively detailed widget information . The default is an empty string .
3、accessibleName : QString -- The name of the part shown in the auxiliary reading . For most widgets , There is no need to set this property . When the widget does not provide any text , Setting this property is very important . The default is an empty string .
4、autoFillBackground : bool -- Whether to automatically fill the widget background . The default is false.
If enabled , This attribute will result in Qt Fill the background of the widget before calling the draw event . The colors used are determined by the... In the widget palette QPalette::Window Of color Role definition . Besides , Unless set WA_OpaquePaintEvent or WA_NoSystemBackground attribute , Otherwise, the window always uses QPalette::Window fill . If the widget's parent has a static gradient background , You cannot disable this property .
When the widget has a style sheet with a valid background or border image , This property will be automatically disabled .
5、baseSize : QSize -- The basic size of the widget . If the widget defines sizeIncrement attribute , Use the base size to calculate the appropriate widget size . The default value is QSize(0,0).
6、childrenRect : QRect -- The border of the widget sub object . Does not contain hidden child objects .
By default , For widgets without children , This property contains a rectangle with zero width and height at the origin .
7、childrenRegion : QRegion -- The crop region occupied by the child of the widget . Does not contain hidden child objects .
By default , For widgets without children , This attribute contains an empty area .
8、contextMenuPolicy : Qt::ContextMenuPolicy -- Menu policy (QWidget Menu policy :Qt::ContextMenuPolicy).
9、cursor : QCursor -- Mouse style . If the mouse is not set , Or calling unsetCursor() after , Will use the parent's mouse . By default , This property contains a with Qt::ArrowCursor style ( arrow ) The mouse .
10、enabled : bool -- Is it available . The default is true.
Generally speaking , Enabled widgets handle keyboard and mouse events , Disabled widgets do not handle (QAbstractButton exception ). Some widgets display differently when disabled . for example , The button may draw its label in gray .
If the widget needs to know when it is enabled or disabled , You can use the type QEvent::EnabledChange Of changeEvent().
Disabling a widget implicitly disables all its children , Enable will enable all child widgets , Unless they have been explicitly disabled . When the parent widget remains disabled , It is not possible to explicitly enable child widgets that are not window types .
11、focus : bool -- Whether there is keyboard input focus . The default is false.
12、focusPolicy : Qt::FocusPolicy -- Focus strategy (QWidget Focus strategy :Qt::FocusPolicy).
13、font : QFont -- typeface (QFont Detailed explanation ).
14、frameGeometry : QRect
15、frameSize : QSize --frameGeometry() The width and height of , See above .
16、fullScreen : bool -- Whether the status is displayed in full screen .
17、geometry : QRect -- See above .
18、height : int / width : int / x : int / y : int -- See above .
19、inputMethodHints : Qt::InputMethodHints -- Input prompt for input type part .
This is only relevant for input widgets . Input methods use it to retrieve tips about how the input method should operate . for example , If set Qt::ImhFormattedNumbersOnly sign , The IME may change its visual components to reflect that only numbers can be entered .
Be careful : The sign is just a reminder , Therefore, specific ime implementations are free to ignore them . If you want to make sure you enter a certain type of character , You should also set... On the widget QValidator. see TextEdit.
To set a flag , Please perform :
w->setInputMethodHints(w->inputMethodHints()|f);
instead of :
w->setInputMethodHints(f);
22、isActiveWindow : bool -- Whether the widget's window is active . An active window is a window that contains widgets with keyboard focus .
21、layoutDirection : Qt::LayoutDirection --QWidget On layout() The layout direction of .(Qt: Layout direction )
22、locale : QLocale -- Area ( practical QLocale).
23、maximized : const bool / minimized : const bool Whether it is currently maximized / Minimized .
24、maximumHeight : int
maximumWidth : int
maximumSize : QSize
Maximum height / Width /size( Pixel values ), Maximum height / The default value for width is 16777215.
25、minimumHeight : int
minimumWidth : int
Minimum height / Width . The default value is 0.
26、minimumSize : QSize
Minimum size. The default is (0,0). The minimum size set by this property will override QLayout Minimum size defined .
27、minimumSizeHint : QSize
Tips for minimum size of layout manager .
When QWidget No layout is set ( namely layout() == nullptr) when , Returns an invalid value (QSize(-1,-1)).
Otherwise return to layout() Minimum size of ( And layout The subassemblies in and layout The spacing of the ).
28、modal : bool
Whether the modal part .
29、mouseTracking : bool.
Whether to enable mouse tracking . The default is false.
If mouse tracking is disabled , The widget only receives mouse movement events when at least one mouse button is pressed while the mouse is moving .
If mouse tracking is enabled , Even if no button is pressed , The widget also receives mouse movement events .
30、normalGeometry : const QRect.
When QWidget As a top-level widget Geometry().
Returns null when treated as a subassembly QRect().
31、palette : QPalette
palette ( practical QPalette). You cannot match a palette with Qt Use with style sheets .
32、pos : QPoint
The position of the widget within its parent widget . If the widget is a window , Its location is the location of the widget on the desktop ( See above ).
Change position :
The widget ( If visible ) Will immediately receive a mobile event (moveEvent()).
If not currently visible , Then a move event will be received before the display .
By default , This property contains a position pointing to the origin .
stay moveEvent() Call in move() or setGeometry() May result in infinite recursion .
33、rect : QRect
be equal to QRect(0,0,width(),height()). See above .
34、size : QSize
be equal to QSize(width(),height()).
If the widget is visible while resizing , It will immediately receive a resizing event (resizeEvent()).
If the widget is not currently visible , An event will be received before the display .
If the size exceeds that specified by minimumSize() and maximumSize() Defined scope , It will be adjusted . The default value of this attribute depends on the user's platform and screen geometry .
stay resizeEvent() Call in resize() or setGeometry() May result in infinite recursion .
Set the size to QSize(0,0) Will cause the widget not to appear on the screen .
35、sizeHint : QSize
and minimumSizeHint be similar .layout() Null returns an invalid value , Otherwise return to layout() Recommended size .
The following is a good way to write :
resize(this->sizeHint());
36、sizeIncrement : QSize
Save the increment of widget size .
When the user resizes the window , The size will be in the horizontal direction in sizeIncrement().width() Pixels and vertical direction in sizeIncrement.height() Pixel by pixel , With baseSize() Based on . The preferred widget size applies to non negative integers i and j:
width = baseSize().width() + i * sizeIncrement().width();
height = baseSize().height() + j * sizeIncrement().height();
Although you can set the size increment for all widgets , But it only affects windows .
By default , This property contains the size with zero width and height .
37、sizePolicy : QSizePolicy
Size strategy (QSizePolicy Detailed explanation ).
38、statusTip : QString
When the mouse is over the control, a prompt message is displayed in the status bar of the window , If the window has no status bar, it does not display .
39、styleSheet : QString
Style sheets , See :https://blog.csdn.net/kenfan1647/category_10854729.html
40、tabletTracking : bool
Whether to enable digital board tracking .
If you disable ( default setting ) When you move the pen , The widget receives tablet movement events only when the stylus contacts the tablet or at least one of the stylus buttons is pressed .
If enabled , Even if you hover the mouse nearby , Widgets also receive tablet movement events .
41、toolTip : QString
The tool tip . By default , Show tooltips only for child widgets of the active window . If you want to control the behavior of tooltips , You can capture QEvent::ToolTip event . By default , This property contains an empty string .
42、toolTipDuration : int
Tooltip display time for widget ( Company : millisecond ). If the value is -1( The default value is ), The duration is calculated according to the length of the tooltip .
43、updatesEnabled : bool 【 Be careful 】
Whether to enable update . If update is disabled , Call update() and repaint() Invalid . The default is true.
Disabling a widget implicitly disables all its children . Enabling widgets enables all child widgets except the top-level widget or all child widgets that have been explicitly disabled . Re enabling updates implicitly invokes... On the widget update().
setUpdatesEnabled() Usually used to disable updates for a short period of time , for example , Avoid screen flickering when making large changes .
setUpdatesEnabled(false);
bigVisualChanges();
setUpdatesEnabled(true);
44、visible : bool
Whether the widget is visible .
When the visibility state of the control changes , It receives show and hide Events . Between hiding events and showing Events , No waste CPU Cycle to prepare or display information to the user .
Widgets that are obscured by other windows on the screen are considered visible .
A spontaneous hidden event occurs when the user minimizes the window , And a spontaneous display event occurs when the window is restored again .
45、whatsThis : QString
Of components “What's This” Help text messages . The default is empty. .
46、windowFilePath : QString
The file path associated with the widget . It associates the file path with the window . If the file path is set , But the window title has not been set , be Qt Will set the window title to use QFileInfo::fileName() Gets the file name of the specified path .
setWindowFilePath(QStringLiteral("D:\\ Study OPenCV3.pdf"));
47、windowFlags : Qt::WindowFlags
Window sign .
When changing the window's flag , Will call setParent(), This causes the widget to be hidden . Must call show() To make the widget visible again .
48、windowIcon : QIcon
Widget icon . If no icon is set , be windowIcon() Return to the application icon (QApplication::windowIcon()).
49、windowModality : Qt::WindowModality
Window modal type . The default is Qt::NonModal.
Qt::Window This attribute is only meaningful for widgets of type .
It is invalid to change this property when the window is visible , Must first hide() The widget , And then again show().
Qt::NonModal: Modeless .
Qt::WindowModal: Mode of a single window hierarchy , Block input to its parent window 、 All grandparent windows 、 All peer windows of its parent window and grandparent window .
Qt::ApplicationModal: Application mode , Block input from all windows .
50、windowOpacity : double
The opacity level of the window . The effective range of opacity is 1.0( Completely opaque ) To 0.0( Completely transparent ). By default , The value of this property is 1.0.
Warning : Changing this property from not transparent to transparent may cause a paint event , You need to process the window correctly to display the window correctly . This mainly affects QScreen::grabWindow() Use . Also pay attention to , Translucent windows are much slower to update and resize than opaque windows .
51、windowTitle : QString
Window title . This property is only available for top-level widgets ( Such as windows and dialog boxes ) meaningful . If no title is set , Then the title is based on windowFilePath. If none of them are set , The title is an empty string .
( To be continued )
边栏推荐
- Process accounting, process time, daemon
- 1. Getting to know R
- Implementation of exec function and shell
- What is a federated index?
- 解释器文件
- [generation confrontation network learning III] reading notes of Bigan paper and its principle understanding
- Unsupported class file major version 60
- sklearn中随机森林RandomForestClassifier的参数含义
- Ctfshow-web266 (deserialization)
- Wechat e-book reading applet graduation design work (6) opening defense ppt
猜你喜欢

在 Traefik Proxy 2.5 中使用/开发私有插件(Traefik 官方博客)

基于微信电子书阅读小程序毕业设计毕设作品(1)开发概要

How to make a computer installation and startup USB flash disk

Demand and business model analysis-3-design

基于微信电子书阅读小程序毕业设计毕设作品(7)中期检查报告

I learned database at station B (10): View

IO流基础知识详解--文件及IO流原理

Wechat e-book reading applet graduation design work (6) opening defense ppt

Wechat e-book reading applet graduation design works (1) development outline

Axure RP 9 for MAC (interactive product prototyping tool) Chinese version
随机推荐
What is an index?
【GAMES101】课堂笔记8–着色(着色频率、图形管线、纹理映射)
测试必备:推荐一款跨平台App性能专项测试工具!
[games101] class note 8 - shading (shading frequency, graphics pipeline, texture mapping)
MySQL日志
When will the index fail
Detailed explanation of IO flow basic knowledge -- file and IO flow principle
MySQL index classification
2 R programming
1. Getting to know R
I learned database at station B (10): View
Wechat e-book reading applet graduation design completion works (8) graduation design thesis template
[generation confrontation network learning III] reading notes of Bigan paper and its principle understanding
3 R complex data types
Theory + practice will help you master the dynamic programming method
EFCore调优
Ctfshow-web265 (deserialization)
Negative remainder problem
Detailed explanation of search tree and hash table
WordPress station group tutorial automatic collection of pseudo original release tutorial