Qt自定义MessageBox窗口
必要元素及其功能
- 标题栏(表头,关闭按钮,自由拖动)
- 内容(不同的图片,提示内容,取消确认按钮)
- 状态阻塞式的模态窗口
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#pragma once #include <QDialog> #include <QObject> #include <QLabel> #include <QPushButton> #include <QToolButton> #include <QMouseEvent> class msg_box_t: public QDialog { Q_OBJECT public: msg_box_t(QString); ~msg_box_t(); protected: QPoint move_point; bool mouse_press; void mousePressEvent(QMouseEvent*); void mouseReleaseEvent(QMouseEvent*); void mouseMoveEvent(QMouseEvent*); public slots: void ok_btn_press(); void cancle_btn_press(); void close_btn_press(); };
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84#include "msg_box.hpp" msg_box_t::msg_box_t(QString text) { this->resize(360,160); this->setObjectName("msg"); int width = this->width(); int height = this->height(); this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog); auto title_lbl_ = new QLabel(this); title_lbl_->setObjectName("title_label_"); title_lbl_->setGeometry(0, 0, width, 32); title_lbl_->setText(u8"提示"); auto close_btn_ = new QPushButton(this); close_btn_->setObjectName("setting_button"); close_btn_->setToolTip(u8"关闭"); close_btn_->setGeometry(width - 33, 1, 32, 32); close_btn_->setIcon(QIcon(":/images/close.png")); auto info_lbl_ = new QLabel(this); info_lbl_->setObjectName("title_label_"); info_lbl_->setText(text); info_lbl_->setGeometry(50, 30, width-100, 70); info_lbl_->setAlignment(Qt::AlignCenter); info_lbl_->setWordWrap(true); auto ok_btn_ = new QPushButton(this); ok_btn_->setText(u8"确定"); ok_btn_->setGeometry(70, height - 20 -32, 100, 32); ok_btn_->setObjectName("msg_btn"); auto cancle_btn_ = new QPushButton(this); cancle_btn_->setText(u8"取消"); cancle_btn_->setGeometry(190, height - 20 - 32, 100, 32); cancle_btn_->setObjectName("msg_btn"); connect(close_btn_, SIGNAL(clicked()), this, SLOT(close_btn_press())); connect(ok_btn_, SIGNAL(clicked()), this, SLOT(ok_btn_press())); connect(cancle_btn_, SIGNAL(clicked()), this, SLOT(cancle_btn_press())); } msg_box_t::~msg_box_t() { } void msg_box_t::mousePressEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton) { mouse_press = true; move_point = event->pos(); } } void msg_box_t::mouseReleaseEvent(QMouseEvent*) { mouse_press = false; } void msg_box_t::mouseMoveEvent(QMouseEvent* event) { if (mouse_press) { QPoint move_pos = event->globalPos(); this->move(move_pos - move_point); } } void msg_box_t::ok_btn_press() { this->accept(); } void msg_box_t::cancle_btn_press() { this->reject(); } void msg_box_t::close_btn_press() { close(); }
最后
以上就是愤怒花卷最近收集整理的关于Qt自定义MessageBox窗口的全部内容,更多相关Qt自定义MessageBox窗口内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复