当前位置:网站首页>QT knowledge: detailed explanation of view frame qgraphicswidget
QT knowledge: detailed explanation of view frame qgraphicswidget
2022-06-23 12:00:00 【Mr anhydrous】
One 、 Abstract
QGraphicsWidget Is an extended base item . It is in many ways related to QWidget be similar , At the same time, it also adds many graphic functions ; Provide a palette 、 typeface 、 style . Also have geometry(),setLayout() etc. .
Two 、 describe
1、QGraphicsWidget Is an extended base item , It's in QGraphicsItem Provides additional functionality over .
Provide a palette 、 typeface 、 style .
Yes geometry().
You can use setLayout() and layout() Support layout .
Support use grabShortcut() and insertAction() And QAction.
And QGraphicsItem Different ,QGraphicsWidget Not an abstract class .
2、 because QGraphicsWidget And QWidget Similar and having similar API, So take the widget from QWidget Migration to QGraphicsWidget Than QGraphicsItem It's easier .
3、QGraphicsWidget Default supported Qt Widget properties are as follows :
Qt::WA_RightToLeft: Indicates that the layout direction of the widget is from right to left .
Qt::WA_SetStyle: Indicates that the widget has its own style . If this property is set ( from setStyle() Set up ), The widget has been explicitly assigned a style . If not set , The widget will use the style of the scene or application .
Qt::WA_Resized: Indicates that the widget has a definite size .
Qt::WA_SetPalette: Indicates that the widget has its own palette .
Qt::WA_SetFont: Indicates that the widget has its own font .
Qt::WA_WindowPropagation: Make the top-level window inherit fonts from its parent 、 Palette and locale .
4、 Even though QGraphicsWidget Inherited from QObject and QGraphicsItem( Both have their own systems for managing sub items ), But you should use QGraphicsItem Features provided ( instead of QObject) To manage the relationship between parent and child items . from QGraphicsItem Control the stacking order and ownership of drawing items .
3、 ... and 、 Attribute members
1、autoFillBackground : bool
Whether to automatically fill the widget background . If enabled , This attribute will result in Qt Calling paint() Method to fill in the background of the widget . The colors used are determined by the... In the widget palette QPalette::Window Color role definitions .QGraphicsWidget Always use QPalette::Window fill , Unless set WA_OpaquePaintEvent attribute ( attribute ). By default, this attribute is false.
2、focusPolicy : Qt::FocusPolicy
The strategy of accepting keyboard focus ( Focus strategy Qt::FocusPolicy).
If the widget handles keyboard events , You must enable keyboard focus for the widget, for example ,QLineEdit Constructor call setFocusPolicy(Qt::StrongFocus).
If you enable the focus policy ( namely , No Qt::NoFocus),QGraphicsWidget Will automatically enable ItemIsFocusable sign ( Graphic item flags ). Set... On the widget Qt::NoFocus Will clear away ItemIsFocusable sign .
3、font : QFont
The font of the widget . This attribute consists of an explicitly defined font attribute and an attribute implicitly inherited from the widget's parent . therefore , And use setFont() Compared with the set font ,font() You can return different Fonts . This scheme allows you to define a single entry in a font , It does not affect the inherited entries of the font .
When the font of the widget changes , It parses its entries according to its parent widget . If the widget does not have a parent widget , It parses its entries according to the scenario . The widget then sends itself a FontChange() Event and notify all its descendants , So that they can also parse their Fonts . By default , This property contains the default font for the application .
4、geometry : QRectF
The geometry of the widget . Set the geometry of the drawing item to rectangle . Calling this function modifies the position and size of the drawing item . The graphic item first moves , Then adjust the size. . A side effect of calling this function is that the widget will receive a move event and a resize event . Besides , If the widget is assigned a layout , The layout will activate .
5、layout : QGraphicsLayout*
Layout of widgets .QGraphicsWidget Ownership of the layout .
6、maximumSize : const QSizeF / minimumSize : const QSizeF / preferredSize : const QSizeF
The maximum size of the widget / Minimum / Preferred size .
7、palette : QPalette
Palette of widgets . The palette provides colors and brushes for color groups , Define the general appearance of widgets and their children .QPalette Consists of explicitly defined color groups and groups implicitly inherited from the widget's parent . therefore ,palette() Can return with setPalette() Set up a different palette . When the widget's palette changes , It parses its entries according to its parent widget , Or if it doesn't have a parent widget , Then the scene will be parsed . Then it sends itself a PaletteChange() event , And inform all its descendants , So that they can also parse their palette . By default , This property contains the application's default palette .
8、size : QSizeF
The size of the widget . This attribute only affects the width and height of the widget . The position and upper left corner of the widget are not affected . Resizing the widget triggers GraphicsSceneResize() event .
9、sizePolicy : QSizePolicy
Size strategy .
10、windowFlags : Qt::WindowFlags
Window sign . A window flag is a window type ( Such as Qt::Dialog) And several flags that provide prompt for window behavior . By default , This property does not contain a window flag . Windows are panels , If set Qt::Window sign , be ItemIsPanel( Graphic item flags ) The flag will be set automatically . If you remove Qt::Window sign , be ItemIsPanel The flag will also be cleared . Be careful ,ItemIsPanel Signs can be independent of Qt::Window Set up .
11、windowTitle : QString
Window title . This property is only used for windows .
Four 、 Member functions
1、void addAction(QAction *action) / void addActions(QList<QAction *> actions)
Add actions to QAction list .QGraphicsWidgets There is one QActions list .
2、void adjustSize()
Resize the widget to its valid preferred size (effectiveSizeHint(Qt::PreferredSize)(QGraphicsLayoutItem)). When drawing items are first displayed , This function is implicitly called .
3、bool close()
Close the widget . If the widget closes successfully , Then return to true, Otherwise return to false. First send a... To the widget QCloseEvent, The widget may or may not accept the event . If the event is ignored , Then do nothing . If the event is accepted , It will close the widget . If the widget is set to Qt::WA_DeleteOnClose attribute , It will be deleted .
4、[ Virtual functions ] bool focusNextPrevChild(bool next)
Press down Tab and Shift+Tab, Find a new widget to focus the keyboard on , If you can find new widgets , Then return to true Otherwise return to false. If next by true, Search forward or search backward .
5、QGraphicsWidget *focusWidget()
If this widget 、 Children or descendants of this widget currently have input focus , This function will return a pointer to the widget .
6、[ The signal ] void geometryChanged()
As long as setGeometry() Change geometry in , It will send out this signal .
7、void getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom)
Get the widget's window margins .
8、int grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context = Qt::WindowShortcut)
towards Qt Add a shortcut key to the shortcut system of (QKeySequence Is a class that encapsulates shortcut key information ), The system operates in a given environment ( Parameters 2) Monitor a given key sequence in .
Qt::ShortcutContext: The context in which the shortcut key is located .
Qt::WidgetShortcut: When the parent widget has focus , Shortcut keys are active .
Qt::WidgetWithChildrenShortcut: When the parent widget or any of its children has focus , Shortcut keys are active .
Qt::WindowShortcut: For widgets that do not belong to Windows ( That is, the top-level widget and its subcomponents ), Shortcut keys apply to the scene .
Qt::ApplicationShortcut: Shortcut keys apply to the entire application .
9、void initStyleOption(QStyleOption *option)
Set the object according to the style (QStyleOption) Set up QGraphicsWidget Widget styles for objects .QStyleOption Object has the following members :
These members are used by default QGraphicsWidget The following properties of :
state & QStyle::State_Enabled:isEnabled()
state & QStyle::State_HasFocus:hasFocus()
state & QStyle::State_MouseOver:isUnderMouse()
direction:layoutDirection()
rect:rect().toRect()
palette:palette()
fontMetrics:QFontMetrics(font())
10、void insertAction(QAction *before, QAction *action) / void insertActions(QAction *before, QList<QAction *> actions)
The parameter 2 The action of is inserted into the parameter 1 Before . If before == nullptr or before Actions that are not the current widget are appended to the action list .
11、bool isActiveWindow()
The widget's window is in the active window , Or the widget has no windows but is in the active scene ( That is, the current scene with focus ) in , Then return to true.( An active window is a window that contains child widgets that currently have input focus or that itself has input focus )
12、[ Virtual functions ] void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr)
Called by the scenario , Draw the window border for the window in local coordinates . The basic implementation uses the current style to render borders and title blocks .
13、void removeAction(QAction *action)
Remove action .
14、void resize(qreal w, qreal h)
Reset width and height .
15、void setAttribute(Qt::WidgetAttribute attribute, bool on = true)
If on by true, This function enables the attribute , Otherwise, the attribute is disabled . Useful properties
16、void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
Set left 、 On 、 Right 、 Content margin under . Layouts use content margins to define the location of child widgets and layouts .
17、void setLayout(QGraphicsLayout *layout)
Setting up layout . Before assigning a new layout , Any existing layout managers... Will be deleted .QGraphicsWidget Ownership of the layout .
18、[static] void setTabOrder(QGraphicsWidget * A, QGraphicsWidget * B)
Set when pressed tab Key focus from A Move to B.
set focus a->b->c->d Move :
setTabOrder(a, b); // a -> b
setTabOrder(b, c); // a -> b -> c
setTabOrder(c, d); // a -> b -> c -> d
19、void setWindowFrameMargins(QMarginsF margins)
Set widget window margins . The default margins are provided by the style , Depends on the current window flag . If you want to draw your own window style , You can set your own frame margins to override the default margins .
20、bool testAttribute(Qt::WidgetAttribute attribute)
Returns whether the widget has properties enabled .
21、void unsetWindowFrameMargins()
Reset border margins to the default values provided by the style .
5、 ... and 、 Event member functions
1、void changeEvent(QEvent *event)
Status change event . Include :
QEvent::ActivationChange
QEvent::EnabledChange
QEvent::FontChange
QEvent::StyleChange
QEvent::PaletteChange
QEvent::ParentChange
QEvent::LayoutDirectionChange
QEvent::ContentsRectChange
2、void closeEvent(QCloseEvent *event)
Widget close event . The default implementation accepts events .
3、bool event(QEvent *event)
Handling events . The following events can be handled :
QEvent::Polish
QEvent::GraphicsSceneMove: The position in the scene changes .
QEvent::GraphicsSceneResize: The size changes in the scene .
QEvent::Show: The widget is displayed on the screen .
QEvent::Hide: Widgets hide .
QEvent::PaletteChange: Palette changes .
QEvent::FontChange: Font change .
QEvent::EnabledChange: Enable state change .
QEvent::StyleChange: Style change .
QEvent::LayoutDirectionChange: The layout direction changes .
QEvent::ContentsRectChange: Content margins / Scope changes .
4、void grabKeyboardEvent(QEvent *event)
Handle QEvent::GrabKeyboard ( Drawing item get keyboard grab ) event .
5、void grabMouseEvent(QEvent *event)
Handle QEvent::GrabMouse( Drawing item get mouse crawl ) event .
6、void hideEvent(QHideEvent *event)
Hidden Events . Called on an event QEvent::accept() or QEvent::ignore() Invalid .
7、void moveEvent(QGraphicsSceneMoveEvent *event)
Mobile event . This event is only passed when the drawing item itself moves . call setTransform() Or moving the ancestor of any drawing item does not affect the local location of the drawing item . Called on an event QEvent::accept() or QEvent::ignore() Invalid .
8、void polishEvent()
This event is passed from the scene to the drawing item at a certain time point after the drawing item is built , The function of this event is to perform the final initialization operation before the graphic item is displayed .
9、void resizeEvent(QGraphicsSceneResizeEvent *event)
Resizing Events . This event is only passed when the widget is resized locally . Call on the widget or any of its ancestors or views setTransform() Does not affect the local size of the widget . Called on an event QEvent::accept() or QEvent::ignore() Invalid .
10、bool sceneEvent(QEvent *event)
from QGraphicsItem::sceneEvent() Re actualize .QGraphicsWidget Of sceneEvent() The implementation simply passes events to QGraphicsWidget::event(). Should not be in QGraphicsWidget Re implement this function in a subclass of .
11、void showEvent(QShowEvent *event)
Show events . Pass this event before the widget is displayed . Called on an event QEvent::accept() or QEvent::ignore() Invalid .
12、void ungrabKeyboardEvent(QEvent *event)
Handle lost keyboard grab Events QEvent::UngrabKeyboard.
13、void ungrabMouseEvent(QEvent *event)
Handle lost mouse grab Events QEvent::UngrabMouse.
14、bool windowFrameEvent(QEvent *event)
Handle window frame Events . Its basic implementation provides support for default window frame interaction , Such as mobile 、 Resize, etc .
边栏推荐
- ROS察微【51】:如何将里程计和 IMU 与 robots_localization 融合
- Where to find capacitance parameters!?
- 目前 在哪里开户是最安全正规的?
- 有没有碰到过flink1.15.0 和 flink-cdc-mysql 2.2.1不兼容的情况?f
- HMS core video editing service has the ability to open templates, helping users get the same cool video with one click
- 汉源高科USB3.0光端机USB工业触摸屏光端机USB3.0光纤延长器USB3.0光纤传输器
- 4K-HDMI光端机1路[email protected] HDMI2.0光端机 HDMI高清视频光端机
- Easy to understand soft route brushing tutorial
- Shell process control - 39. Special process control statements
- 运行时应用自我保护(RASP):应用安全的自我修养
猜你喜欢

汉源高科新一代绿色节能以太网接入工业交换机高效节能型千兆工业以太网交换机

Simulation questions and answers of the latest national fire-fighting facility operators (primary fire-fighting facility operators) in 2022

简单易懂的软路由刷机使用教程

navicat定时任务无效

二維激光SLAM( 使用Laser Scan Matcher )

halcon原理:一维函数function_1d类型【1】

ROS knowledge: point cloud files PCD format

Design of routing service for multi Activity Architecture Design

Meta said that the UK security law may "scan all private information" or infringe privacy

广播级E1转AES-EBU音频编解码器 E1转立体声音频卡侬头(XLR)编解码器
随机推荐
有没有碰到过flink1.15.0 和 flink-cdc-mysql 2.2.1不兼容的情况?f
ESP32-C3入门教程 问题篇⑦—— fatal error: esp_bt.h: No such file or directory 找不到esp_bt.h
电脑坏了,换了台电脑,装node环境的时候出了问题,报错URL not defined
32路电话+2路千兆以太网32路PCM电话光端机支持FXO口FXS语音电话转光纤
Leetcode 1209. 删除字符串中的所有相邻重复项 II(初版本没过)
股票网上开户及开户流程怎样?手机开户安全么?
The list of open source summer winners has been publicized, and the field of basic software has become a hot application this year
Use xtradiagram Diagramcontrol for drawing and controlling process graphics
Oversampling series I: sampling theorem and oversampling rate
[comprehensive written test questions] 30 Concatenate substrings of all words
Runtime application self-protection (rasp): self-cultivation of application security
Redis 入门-第二篇-数据结构与对象-链表
目前 在哪里开户是最安全正规的?
Where is the safest and most formal way to open an account at present?
QT5知识:DNS查询
Is there any regulation on the redemption time of financial products?
ROS知识:点云文件.pcd格式
Slam Laser 2D (en utilisant Laser Scan matcher)
年薪中位数超30万,南大AI专业首届毕业生薪资曝光
如何卸载Gazebo与重装