当前位置:网站首页>QT basic day 2 (2) QT basic components: button class, layout class, output class, input class, container and other individual examples
QT basic day 2 (2) QT basic components: button class, layout class, output class, input class, container and other individual examples
2022-07-29 07:21:00 【Fly 】
We said that before qt Basic development process of program
1. State the necessary components
2. Construct components
3. Necessary layout
4. Front and back desk Association
5. beautify
Today we will continue to talk about qt Basic components of .
One . Button class
Push Button
: Button
Tool Button
: Tool button
Radio Button
: Radio button
Check Button
: Check box
Command Link Button
: Command link button
Dialog Button Box
: Dialog box button box
Example :
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
#include <QToolButton>
#include <QRadioButton>
#include <QCheckBox>
#include <QCommandLinkButton>
#include <QLineEdit>
class Widget : public QWidget
{
Q_OBJECT
public slots:
void xxx(bool x);
void showpass(bool);
public:
Widget(QWidget *parent = 0);
~Widget();
private:
QPushButton *bt_button; // General button
QToolButton *bt_tool; // Tool button
QRadioButton *bt_radio; // Radio button
QRadioButton *bt_radio1;// Radio button
QCheckBox *bt_check; // Check button
QCheckBox *bt_check1; // Check button
QCommandLinkButton *bt_cmd;// Command button
QLineEdit *le;
QCheckBox *ck;
};
#endif // WIDGET_H
#include "widget.h"
#include <QVBoxLayout>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
bt_button = new QPushButton(" General button ");
bt_tool = new QToolButton;
bt_tool->setText(" Tool button ");
bt_radio = new QRadioButton(" Radio button ");
bt_radio1 = new QRadioButton(" Radio button 1");
bt_check = new QCheckBox(" Check box ");
bt_check1 = new QCheckBox(" Check box 1");
bt_cmd = new QCommandLinkButton(" Baidu ");
bt_cmd->setDescription("www.baidu.com");
// application
le = new QLineEdit;
le->setEchoMode(QLineEdit::Password);
ck = new QCheckBox(" Display password ");
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(bt_button);
vbox->addWidget(bt_tool);
vbox->addWidget(bt_radio);
vbox->addWidget(bt_radio1);
vbox->addWidget(bt_check);
vbox->addWidget(bt_check1);
vbox->addWidget(bt_cmd);
vbox->addWidget(le);
vbox->addWidget(ck);
setLayout(vbox);
// connect(bt_button, SIGNAL(clicked(bool)), this, SLOT(xxx(bool)));
// connect(bt_radio, SIGNAL(toggled(bool)), this, SLOT(xxx(bool)));
connect(bt_check, SIGNAL(toggled(bool)), this, SLOT(xxx(bool)));
connect(ck, SIGNAL(toggled(bool)), this, SLOT(showpass(bool)));
}
void Widget::showpass(bool x)
{
if(!x)
le->setEchoMode(QLineEdit::Password);
else
le->setEchoMode(QLineEdit::Normal);
}
void Widget::xxx(bool x)
{
qDebug() << x;
}
Widget::~Widget()
{
}
Two . Layout class
Vertical Layout
: Vertical layout
Horizontal Layout
: Horizontal layout
Grid Layout
: Grid layout
Form Layout
: Form layout
3、 ... and . Output class
Label: label
Text Browser: Text browser
Graphics View: Graphic view
Calendar Widget: The calendar
LCD Number: LCD Digital
Progress Bar: Progress bar
Horizontal Line: Level
Vertical Line: Vertical line
OpenGL Widget:OpenGL Tools
QQuickWidget: The embedded QML Tools
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QLabel>
#include <QTextBrowser>
#include <QCalendarWidget>
#include <QDate>
#include <QLCDNumber>
#include <QProgressBar>
class Widget : public QWidget
{
Q_OBJECT
public slots:
void showDate(QDate);
void update_value(void);
public:
Widget(QWidget *parent = 0);
~Widget();
private:
QLabel *lb_text; // Text label
QLabel *lb_pix; // Picture label
QLabel *lb_gif; // Animated tags
QTextBrowser *tbrowser;
QCalendarWidget *caw;
QLCDNumber *lcd;
QProgressBar *pbr;
};
#endif // WIDGET_H
#include "widget.h"
#include <QVBoxLayout>
#include <QMovie>
#include <QTimer>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
/* label */
lb_text = new QLabel(" Label testing ");
lb_text->setAlignment(Qt::AlignCenter);
lb_pix = new QLabel(" I'm the picture ");
lb_pix->setMinimumSize(10, 10);
lb_pix->setScaledContents(true); // Auto zoom display
lb_pix->setPixmap(QPixmap("C:\\Users\\ThinkPad T490\\Desktop\\220501\\1.bmp"));
lb_gif = new QLabel(" I am animation ");
QMovie *m = new QMovie("C:\\Users\\ThinkPad T490\\Desktop\\220501\\1.gif");
lb_gif->setMovie(m);
m->start();
/* Text browser (html)*/
tbrowser = new QTextBrowser;
tbrowser->setText("<!DOCTYPE html>\
<html>\
<head>\
<meta charset=\"utf-8\">\
<title>runoob.com</title>\
</head>\
<body>\
<h1 >AAAAAAAA</h1>\
<p style=\"background-color:rgb(255,0,0)\">BBBBBBBBB</p>\
</body>\
</html>");
/* Calendar window */
caw = new QCalendarWidget;
/* Seven digital tubes */
lcd = new QLCDNumber;
lcd->setMinimumHeight(50);
lcd->display(250); // Show numbers
/* Progress bar */
pbr = new QProgressBar;
pbr->setValue(60);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(pbr);
vbox->addWidget(lcd);
vbox->addWidget(caw);
vbox->addWidget(tbrowser);
vbox->addWidget(lb_text);
vbox->addWidget(lb_pix);
vbox->addWidget(lb_gif);
setLayout(vbox);
connect(caw, SIGNAL(clicked(QDate)), this, SLOT(showDate(QDate)));
QTimer *t = new QTimer;
connect(t, SIGNAL(timeout()), this, SLOT(update_value()));
t->start(100);
}
void Widget::update_value(void)
{
static int data = 0;
lcd->display(data);
pbr->setValue(data);
data++;
if(data == 100)
data = 0;
}
void Widget::showDate(QDate d)
{
lb_text->setText(d.toString());
}
Widget::~Widget()
{
}
Four . Input class
Combo Box: Combo box
/* Combo box 、 A drop-down box */
cmb = new QComboBox; // Construct combo box
cmb->addItem("C:\\Users\\ThinkPad T490\\Desktop\\220501\\1.bmp");
cmb->addItem("C:\\Users\\ThinkPad T490\\Desktop\\220501\\pc.bmp");
cmb->addItem("C:\\Users\\ThinkPad T490\\Desktop\\220501\\x.jpg");
connect(cmb, SIGNAL(activated(int)), this, SLOT(show_int(int)));
connect(cmb, SIGNAL(activated(QString)), this, SLOT(show_str(QString)));
connect(cmb, SIGNAL(activated(QString)), lb, SLOT(setText(QString)));
//connect(cmb, &QComboBox::activated, [&](int i) { lb->setPixmap(QPixmap(cmb->itemText(i)));});
connect(cmb, SIGNAL(activated(QString)), this, SLOT(show_pic(QString)));
Font Combo Box: Font combo box
/* Font drop-down box */
fcmb = new QFontComboBox;
connect(fcmb, &QFontComboBox::currentFontChanged, [&](QFont f){ lb->setFont(f);});
Line Edit: Row edit box
/* Row edit box */
le = new QLineEdit;
le->setPlaceholderText(" user name ");
Text Edit: Text edit box
/* Text edit box */
te = new QTextEdit;
connect(te, SIGNAL(textChanged()), this, SLOT(te_to_lb()));
Plain Text Edit: Plain text edit box
Spin Box: Digital display box ( Rotating box )
/* Spin frame */
sb = new QSpinBox;
sb->setMaximum(20); // Maximum can only be 20
sb->setSingleStep(10); // Set the single step span
connect(sb, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
Double Spin Box:Double Digital display box
Time Edit: Time edit
/* Time edit box */
timee = new QTimeEdit;
connect(timee, SIGNAL(timeChanged(QTime)), this, SLOT(show_time(QTime)));
Date Edit: Date editing
Date/Time Edit: date / Time edit
Dial: dial
Horizontal Scroll Bar: Horizontal scroll bar
Vertical Scroll Bar: Vertical scroll bar
/* Scroll bar */
slb = new QScrollBar;
slb->setRange(0, 1000); // Set the adjustment range
slb->setOrientation(Qt::Horizontal); // Display scheme “ level ”
connect(slb, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
Horizontal Slider: Horizontal slider
Vertical Slider: Vertical slider
/* Slide the lever */
sd = new QSlider;
sd->setRange(0, 1000); // Set the adjustment range
sd->setOrientation(Qt::Horizontal); // Display scheme “ level ”
connect(sd, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
Key Sequence Edit: Key sequence edit box
5、 ... and . Container class
Group Box: Group box
lb[0] = new QLabel(" subject 1 safasfasfasdf");
rb[0] = new QRadioButton("aaaaa");
rb[1] = new QRadioButton("bbbbb");
rb[2] = new QRadioButton("ccccc");
QVBoxLayout *vbox1 = new QVBoxLayout;
vbox1->addWidget(lb[0]);
vbox1->addWidget(rb[0]);
vbox1->addWidget(rb[1]);
vbox1->addWidget(rb[2]);
g1 = new QGroupBox("AAAA"); // Container with border display and annotation
g1->setLayout(vbox1);
Scroll Area: Scroll area
Tool Box: hold-all
Tab Widget: Label component
Stacked Widget: Stack parts
Frame: frame
Widget: The widget
MDI Area:MDI Area
Dock Widget: Dock form part
QAxWidget: encapsulation Flash Of ActiveX Control
6、 ... and . Space interval group
Horizontal Spacer
: Horizontal spacing
Vertical Spacer
: Vertical spacing
7、 ... and . Project view group
List View
: List view
Tree View
: Tree view
Table View
: Tabular chart
Column View
: Column view
Undo View
: Undo view
8、 ... and . Project control group
List Widget
: List control
Tree Widget
: Tree control
Table Widget
: Table control
Object-oriented thinking :
Example :
qustion.h
#ifndef QUSTIONWIDGET_H
#define QUSTIONWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QRadioButton>
#include <QVBoxLayout>
class qustionWidget : public QWidget
{
Q_OBJECT
public:
qustionWidget(QWidget *parent = nullptr);
public:
void setquestion(QString str); // Set the topic
void addAnswer(QString str); // Add options
private:
QLabel *lb; // Show title
//QVector<QRadioButton *> bt;
QVBoxLayout *vbox; // Display options
};
#endif // QUSTIONWIDGET_H
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include "qustionwidget.h"
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
qustionWidget *q1;
qustionWidget *q2;
qustionWidget *q3;
};
#endif // WIDGET_H
qustiopn.cpp
#include "qustionwidget.h"
qustionWidget::qustionWidget(QWidget *parent) :
QWidget(parent)
{
lb = new QLabel;
//bt.clear();
vbox = new QVBoxLayout;
vbox->addWidget(lb);
setLayout(vbox);
}
void qustionWidget::setquestion(QString str)
{
lb->setText(str);
}
void qustionWidget::addAnswer(QString str)
{
QRadioButton *an = new QRadioButton(str);
vbox->addWidget(an);
}
widget.cpp
#include "widget.h"
#include <QVBoxLayout>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
q1 = new qustionWidget; // subject “ Control ”
q1->setquestion("xxxxxxxxxxxxxxxxxxxxxxxxxxx");
q1->addAnswer("aaaaaaa");
q1->addAnswer("bbbbbbb");
q1->addAnswer("ccccccc");
q1->addAnswer("dddddddddd");
q2 = new qustionWidget; // subject “ Control ”
q2->setquestion("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy");
q2->addAnswer("xxxxx");
q2->addAnswer("yyyyyy");
q2->addAnswer("zzzzzzzzzzzzz");
q3 = new qustionWidget; // subject “ Control ”
q3->setquestion("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy");
q3->addAnswer("xxxxx");
q3->addAnswer("yyyyyy");
q3->addAnswer("zzzzzzzzzzzzz");
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(q1);
vbox->addWidget(q2);
vbox->addWidget(q3);
setLayout(vbox);
}
Widget::~Widget()
{
}
effect :
边栏推荐
- 使用VsCode配置MySQL实现连接、查询、等功能
- 自定义事件
- After 4 years of development and 13K, if you want to change to automated testing, can your salary still rise···
- SpingBoot整合Quartz框架实现动态定时任务(支持实时增删改查任务)
- Round avatar of user list and follow small blocks
- Zabbix 其他基础监控项
- 力扣(LeetCode)209. 长度最小的子数组(2022.07.28)
- OCR光学字符识别方法汇总
- WPF interface layout must know basis
- 我想问一下,我flink作业是以upsert-kafka的方式写入数据的,但是我在mysql里面去更
猜你喜欢
Guess the number / / generate a random number for the first time
Scala 高阶(十):Scala中的异常处理
Operator3-设计一个operator
Image noise and matrix inversion
利用C语言巧妙实现棋类游戏——三子棋
QT基础第二天(2)qt基础部件:按钮类,布局类,输出类,输入类,容器等个别举例
MySQL advanced (Advanced) SQL statement (I)
dba
[OpenGL] use of shaders
MySQL uses the client and select methods to view the summary of blob type fields
随机推荐
如何与斯堪尼亚SCANIA建立EDI连接?
用户列表 圆形头像并跟随小板块
Gin template
【Unity实战100例】Unity万能答题系统之单选多选判断题全部通用
WPF嵌套布局案例
SpingBoot整合Quartz框架实现动态定时任务(支持实时增删改查任务)
Job 7.28 file IO and standard IO
JS 鸡生蛋与蛋生鸡问题,Object与Function究竟谁出现的更早?Function算不算Function的实例?
[C language brush leetcode] 2332. The latest time to get on the bus (m)
Redis基础篇
20-40k | mecarmand 3D vision algorithm / software / Product Manager Recruitment
Custom events
能在SQL 语句中 指定 内存参数吗?
对Vintage分析的一些学习理解
Tp6 use protobuf
Gin Middleware
Student achievement ranking system based on C language design
Nodejs安装教程
vue-router路由缓存
thinkphp6 实现数据库备份