当前位置:网站首页>Common forms in QT
Common forms in QT
2022-06-21 22:55:00 【Clown's stage】
Qwidget
1. brief introduction :
QWidget Class is the base class for all user interface objects . It receives the mouse from the window system , Keyboard and other events , And draw itself on the screen .
Simultaneous inheritance :QObject class and QPaintDevice class
QWidget: Class is the base class for all user interface objects .QObject: It's allQtClass base class . Provides a signal - Slot mechanism .QPaintDevice: have access toQPainterThe base class of the drawn object .
2. Constructors
QWidget::QWidget( QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags() );
parent: If it is nullptr, The widget will become a main window , Otherwise the widget will become parent When a child window in deletes its parent window , Will delete his widget .
f: Bitwise marked by any window “ or ” Value of composition .Qt::Window Flags() Is to construct a template class object. The default is Qt::Widget
3. Member functions
Moving functions :
void move(const QPoint &) void move(int x, int y)
// Set the color ( Commonly used with color fill sets )
void setPalette(const QPalette &)
// Color fill
void setAutoFillBackground(bool enabled)
// Set the font
void setFont(const QFont &);
// Set mouse tracking Events
void setMouseTracking(bool enable);
// The widget
QWidget *widget=new QWidget(nullptr,Qt::Window);
// Set the window title :
widget->setWindowTitle(QStringLiteral(" This is because QWidget forms "));
//widget->setToolTip(QStringLiteral(" This is a hint "));
// Set the icon of the window
widget->setWindowIcon(QIcon("F:\\qtItem\\oftenForms\\image\\11.jpg"));
// Set the state of the window :
widget->setWindowState(Qt::WindowNoState);// The normal state
//widget->setWindowState(Qt::WindowMinimized);// Stay small
//widget->setWindowState(Qt::WindowMaximized);// Maximum state
//widget->setWindowState(Qt::WindowFullScreen);// Full screen , There are no buttons to maximize or minimize ;
//widget->setWindowState(Qt::WindowActive);// Active window , I don't know what's the use
// Set window transparent reading
widget->setWindowOpacity(0.7);
// Hide form :
// widget->hide();
// Closing Windows
//widget->close();
// Set window fixed size
//widget->setFixedSize(400,400);
// Set the cursor
widget->setCursor(Qt::CrossCursor);
// Display window
widget->show();4. attribute :
enabled Enable or disable widget, Enabled by default .
geometry widget Location and size of
3.sizePolicy Set up widget Horizontal and vertical scaling strategies and scaling factors , The so-called scaling strategy is actually widget treat sizeHint The strategy of ,
palette: palette
Value attribute Meaning Fixed Think sizeHint Value is optimal ,widget The size cannot be changed Minimum Think sizeHint The value is the minimum , The size can be increased , It can't be smaller Maximum Think sizeHint Value is maximum , The size can be reduced , Can't get bigger Preferred Think sizeHint Is the appropriate value , The size can be changed , But it is not recommended to get bigger Expanding Think sizeHint Is the appropriate value , The size can be changed , Than Preferred Suitable for getting bigger MinimumExpanding Think sizeHint Is minimum , The size can be increased , It can't be smaller Ignored Ignore sizeHint size , The size can be changed
QFrame( Form with border )
brief introduction :
1.QFrame And QWidget The difference between :
QFrame Is the base class of the basic control ,QWidget yes QFrame Parent class .
QFrame stay QWidget Provides control of the form border based on .
Function :
It mainly controls some border styles , for example : Bulge , Concave , shadow , Line width ;
attribute :
frameRect : QRect : Draw the rectangle of the frame . By default, the entire widget . When the widget changes size , The frame rectangle adjusts automatically .
frameShadow : Shadow: Frame style frame shadow .
frameShape : Shape : Frame shape of frame style .
frameWidth : const int : The width determined by the style frame . for example ,NoFrame The frame width of the specified style is always 0, and Panel The specified style frame width is equal to lineWidth.
lineWidth : int : The width of the frame .
A frame used as a separator (HLine and VLine) Of lineWidth from frameWidth Appoint .
midLineWidth : int : The width of an extra line in the middle of the frame , It uses a third color to get a special 3D effect . Bulge only (raised) Or sunken (sunken) Of Box、HLine、VLine Draw the centerline of the frame .
type :
1、enum QFrame::Shadow: This enumeration type definition is used to provide 3D The shadow type of the effect .
Plain: The frame and content are flush with the surroundings . Use the palette QPalette::WindowText Color painting ( There is no 3D effect ) Raised: The frame and content are raised ; Draw using the light and dark colors of the current color group 3D Raised line Sunken: The frame and content are sunken ; Draw using the light and dark colors of the current color group 3D Sag line 2、enum QFrame::Shape: This enumeration type defines the shapes of the available frames .
NoFrame: Draw nothing Box: Draw a box around its contents Panel: Draw a panel , To make the contents appear convex or concave StyledPanel: Draw a rectangular panel , Its appearance depends on the current GUI style . It can be convex or concave HLine: Draw a horizontal line , No frame ( Use as separator ) VLine: Draw a vertical line , No box ( Use as separator ) WinPanel: Draw a rectangular panel , It can look like Windows 2000 Raised or sunken like a panel in . Specifies that this shape sets the lineweight to 2 Pixels . Provide WinPanel For compatibility . about GUI Style independence , It is suggested to use it instead StyledPanel
application
// First step : Create a QFrame object
QFrame frame;
//frame.setStyleSheet()
// Set border width
frame.setLineWidth(10);
// Set the center line
frame.setMidLineWidth(5);
// Set shape
frame.setFrameShape(QFrame::Box);
// Set the background color of the window
//frame.setStyleSheet("background-color:red");
// Set shadow
frame.setFrameShadow(QFrame::Raised);
// Set border position Draw the rectangular size of the frame ;
frame.setFrameRect(QRect(10,0,400,400));
// Get the width of the border
qDebug()<< frame.lineWidth();
frame.show();QDialog( Dialog box )
brief introduction :
Inherited from Qwidget, Is a container type component ;
When QWidget As a separate window when there is no parent component , When there is a parent component , Embed as a visible part into the parent component .
QDialog Cannot be embedded as a child in another container ;
QGroupBox( Group box )
QGroupBox Provides support for building group boxes . Group boxes usually have a border and a title bar , Used as a container part , Various window components can be arranged in it . Can be used as a container for a set of controls when laying out , But here's the thing , Layout controls must be used internally ( Such as QBoxLayout) Progressive cloth game .
attribute :
alignment: Qt::Alignment
Alignment of group box titles . The default is Qt::AlignLeft.
Qt::AlignLeft: Left alignment .
Qt::AlignRight: right justify .
Qt::AlignHCenter: align horizontal center .
checkable : bool :
Whether there is a check box in the title .
If this check box is selected , Then enable the sub items of the group box ; otherwise , They will be disabled and inaccessible .
checked : bool Whether the check box is selected .
flat : bool
Is it flattened .
A group box usually consists of a surrounding frame with a title at the top . If this property is enabled , Then most styles only draw the top of the frame ; otherwise , The entire frame will be drawn .
Be careful : In some styles , A flat group box and a non flat group box have similar representations , And may not be as distinguishable as in other styles .
title : QString
Title Text .
If the title contains and symbols ('&') Followed by a letter , The group box title text will have keyboard shortcuts .
g->setTitle("&User information");In the example above ,Alt+U Move keyboard focus to group box .
usage
// First step :
QHBoxLayout *box1=new QHBoxLayout(this);
QLabel *label1=new QLabel(QStringLiteral(" male "));
QLabel *label2=new QLabel(QStringLiteral(" Woman "));
QCheckBox *check1=new QCheckBox;
QCheckBox *check2=new QCheckBox;
QHBoxLayout *box2=new QHBoxLayout;
box2->addWidget(check1);
box2->addWidget(label1);
box2->addWidget(check2);
box2->addWidget(label2);
QGroupBox *group=new QGroupBox(QStringLiteral(" Gender "));
group->setCheckable(true);// Sets whether the check box displays
group->setChecked(false);// if true, Then the group box can use , Otherwise, the group box is unavailable
group->setAlignment(Qt::AlignHCenter);// Set the location of the information
group->setLayout(box2);
box1->addWidget(group);
QScrollArea( Scroll area )
brief introduction :
QScrollArea Used as a container part , Provide a scrollable area form . When internal controls cannot be fully displayed ,QScrollArea You can scroll up and down or left and right to display . Be careful : Use QScrollArea It's usually through setWidget Method to add a QFrame object .
attribute :
usage :
// Create a child window , This sub window is given to the scrolling area
QWidget* pSubWidget = new QWidget();
// At the window (100,100) Position display 150*150 Size scrolling area
QScrollArea* pScrollArea = new QScrollArea(this);
//pScrollArea->setFixedSize(350, 150);
// Set whether to automatically resize the part . The default is false.
//pScrollArea->setWidgetResizable(true);
// Format alignment
pScrollArea->setAlignment(Qt::AlignHCenter);
pScrollArea->move(QPoint(100, 100));
// Set the vertical scrolling policy
pScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// Settings settings QScrollArea( Scroll area ) Sizing strategy for
pScrollArea-> setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
// Set a vertical layout object for the child window , Add buttons dynamically , The child window will automatically resize
QVBoxLayout* pSubLayout = new QVBoxLayout(this);
pSubWidget->setLayout(pSubLayout);
for (auto i = 0; i < 10; ++i)
{
pSubLayout->addWidget(new QPushButton(QString("test%1").arg(i), this));
}
pScrollArea->setWidget(pSubWidget);QToolBox hold-all
brief introduction :
QToolBox Class provides a list of tabbed widget items . Inherited from Qframe;
A toolbox is a widget , It displays a list of tabs one by one , The current item is displayed below the current tab . Each tab There is an index position in each tab column . The tab item is a QWidget.
attribute :
count : const int This property holds the number of items contained in the toolbox .
currentIndex : int This property holds the index of the current item
Method :
// Add items to the toolbox , You can specify the text content and icon content of the item
int addItem(QWidget *widget, const QIcon &iconSet, const QString &text)
int addItem(QWidget *w, const QString &text)
// In the toolbox index Insert item at , You can specify the text content and icon content of the item int insertItem(int index, QWidget *widget, const QIcon &icon, const QString &text) int insertItem(int index, QWidget *widget, const QString &text)
// Sets whether items are available according to the index void setItemEnabled(int index, bool enabled)
// Set the icon of the item according to the index void setItemIcon(int index, const QIcon &icon)
// Set the text of the item according to the index void setItemText(int index, const QString &text)
// Set the prompt content of the item according to the index void setItemToolTip(int index, const QString &toolTip)
QTabWidget( Label form )
QTabWidget It is mainly used for pagination display , One interface per page , Many interfaces share a common area , Save interface size , very It is convenient to display more information for users .
Common methods
// Add a page at the end of the label form , And set the form of the page , Tag name and tag icon int addTab(QWidget *page, const QString &label) int addTab(QWidget *page, const QIcon &icon, const QString &label) // In the label form index Position inserts a page , And set the form of the page , Tag name and tag icon int insertTab(int index, QWidget *page, const QString &label) int insertTab(int index, QWidget *page, const QIcon &icon, const QString &label) // Set whether the label can be moved void setMovable(bool movable) // Set the display position of the label void setTabPosition(TabPosition) // Set whether the label is available void setTabEnabled(int index, bool enable) // Set whether the label can be closed void setTabsClosable(bool closeable) // Set the current label index or form void setCurrentIndex(int index) void setCurrentWidget(QWidget *widget)
Enumeration type :QTabWidget::TabPosition
| name | value | explain |
|---|---|---|
| QTabWidget::North | 0 | To the north |
| QTabWidget::South | 1 | Southward direction |
| QTabWidget::West | 2 | Westward |
| QTabWidget::East | 3 | To the East |
QListWidget List form
QListWidget( List form ) Is an item based (item) List form of . The parent class is QListView, Is based on Model( model type ) List view of . QListWidget( List form ) Contains a series of commonly used list form operation interfaces . It can meet the requirements of the general list seek . Can pass QListWidgetItem Set items .
Method list
// Add items to the list form , You can specify the name of the item , The object of the item . Or add multiple items at once void addItem(const QString &label) void addItem(QListWidgetItem *item) void addItems(const QStringList &labels) // Insert item void insertItem(int row, QListWidgetItem *item) void insertItem(int row, const QString &label) void insertItems(int row, const QStringList &labels) // obtain row The item pointer of the line QListWidgetItem *item(int row) const // Find items in the list according to their contents and related rules QList<QListWidgetItem *> findItems(const QString &text, Qt::MatchFlags flags) const // Set the currently selected row or item void setCurrentItem(QListWidgetItem *item) void setCurrentItem(QListWidgetItem *item, QItemSelectionModel::SelectionFlags command) void setCurrentRow(int row) void setCurrentRow(int row, QItemSelectionModel::SelectionFlags command) // Set whether items are sorted when they are added , No sort by default , Display in the order of addition . Set to true Display in ascending order . void setSortingEnabled(bool enable) // Sort all items . The default is ascending . void sortItems(Qt::SortOrder order = Qt::AscendingOrder) // The setting item is editable , void closePersistentEditor(QListWidgetItem *item) // Close the editable state of the item void openPersistentEditor(QListWidgetItem *item) // clear list void clear() // The signal // Send this signal when the selected item changes void currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) // This signal is sent when the current line changes void currentRowChanged(int currentRow) // Send this signal when the current item changes , The parameter is the text of the current item void currentTextChanged(const QString ¤tText) // When item This signal is sent when it is active .( Double click the mouse or click ) void itemActivated(QListWidgetItem *item) // When item This signal is sent when the content of changes void itemChanged(QListWidgetItem *item) // When the mouse clicks item Send the signal when void itemClicked(QListWidgetItem *item) // When the mouse double clicks item Send the signal when void itemDoubleClicked(QListWidgetItem *item) // When the mouse enters item Send the signal when , You have to set setMouseTracking by true void itemEntered(QListWidgetItem *item) // When the mouse goes away item Send the signal when , You have to set setMouseTracking by true void itemPressed(QListWidgetItem *item) // This signal is sent when the selected middle item changes void itemSelectionChanged()
QStackedWidget Stack forms
Stack form (QStackedWidget) Can contain multiple forms , But only one form is displayed . You can set the cable To set the contents of the displayed form . Inherited from 、QFrame;
attribute
count : const int currentIndex : int
function
int addWidget(QWidget *widget): int count() const int currentIndex() const QWidget *currentWidget() const int indexOf(QWidget *widget) const int insertWidget(int index, QWidget *widget) void removeWidget(QWidget *widget) QWidget *widget(int index) const
QTableWidget( Table form )
QToolBar
attribute
allowedAreas : Qt::ToolBarAreas Area where tools can be placed
floatable:bool: This property saves whether the toolbar can be dragged and dropped as a separate window . The default is true
floating : const bool This property saves whether the toolbar is a separate window . The default is true
iconSize : QSize
movable : bool This attribute holds whether users can move toolbars within the toolbar area , Or move toolbars between toolbar areas
orientation : Qt::Orientation Define the orientation of the toolbar
toolButtonStyle : Qt::ToolButtonStyle
function
QT Standard dialog box for
QT Provides some basic dialog types :
Standard file dialog (QFileDialog)
Standard color dialog box (QColorDialog)
Standard font dialog box (QFontDialog)
Standard input dialog box (QInputDialog)
Standard message dialog box (QMessageBox)
边栏推荐
- WPF 启动带参数
- Using JS function in wxml file of applet
- 个人的股票交易经验
- Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
- C# 删除正在使用的文件
- Niuke month race - insectivores on the ring
- 必读书籍
- 《MATLAB 神经网络43个案例分析》:第9章 离散Hopfield神经网络的联想记忆——数字识别
- WPF 手写板
- Fedora 36 compiling and installing opencv 4.6.0 -- the road to building a dream
猜你喜欢

语音断点检测(短时改进子带谱熵)

Translation software Bob installation tutorial

Left hand code, right hand open source, part of the open source road
![[WUSTCTF2020]朴实无华-1](/img/b3/3ea7ead040bca84fb9a67d21bf8170.png)
[WUSTCTF2020]朴实无华-1

【强烈推荐】Markdown 语法大全

Apache ShardingSphere 5.1.2 发布|全新驱动 API + 云原生部署,打造高性能数据网关

WPF dependent properties

Design and implementation of spark offline development framework

Matlab2020a how to export exe using app Designer

. File header parsing of BMP pictures
随机推荐
软件测试概念篇
FPGA之道——数字系统之间的接口电平标准
Flink real-time risk control rule engine
【强烈推荐】Markdown 语法大全
Swiftui basic learning journal (XI) SQLite data operation
关于lg(n!)的渐进紧确界
阿里出品!图形化的ant脚本——IDEA插件CloudToolkit
Wonderful review Figure 1 learn about Huawei cloud special dry goods
牛客月赛-环上食虫
Pycharm使用指南
Synplify Pro的常用选项及命令
Guys, some field updates of starrocks PK model in 2.2.1 still do not support SQL, right?
Specific methods of using cloud development to realize wechat payment
必讀書籍
Uwp shadow effect
KVM虚拟机在线扩展磁盘 —— 筑梦之路
更好的管理各种音乐,专业的DJ音乐管理软件Pioneer DJ rekordbox
在商业智能BI开发过程中,什么问题的挑战性最大?
Design and implementation of spark offline development framework
The way of FPGA -- project scheme and FPGA design scheme of FPGA development process