当前位置:网站首页>QT learning 20 standard dialog box in QT (middle)
QT learning 20 standard dialog box in QT (middle)
2022-07-03 13:58:00 【A little black sauce】
Qt Study 20 Qt Standard dialog boxes in ( in )
Color dialog
- Qt Provided in predefined Color dialog QColorDialog class
- QColorDialog Class is used to provide Dialog box for specifying colors
- How to use the color dialog
// Construct color dialog objects
QColorDialog dlg(this);
// Set the relevant properties of the color dialog
dlg.setWindowTitle("Color Editor");
dlg.setCurrentColor(Qt::red); // Initial color
if (dlg.exec() == QColorDialog::Accepted) {
qDebug() << dlg.selectedColor();
}
- Qt Medium QColor Class is used to represent the concept of color in programs
- QColor Class also supports Multiple color representations
- RGB: In red , green , Three color model based on blue
- HSV: In tone , saturation , Based on lightness Hexagonal cone model
- CMYK: With sky blue , magenta , yellow , Black based Full color printing color model
Input Dialog
- Qt Provided in predefined Input dialog box QInputDialog class
- QInputDialog Class used Occasions requiring temporary data input
- How to use the input dialog
// Construct the input dialog
QInputDialog dlg(this);
// Set the relevant properties of the input dialog
dlg.setWindowTitle("Input ...");
dlg.setLabelText("Please enter a integer: ");
dlg.setInputMode(QInputDialog::IntInput);
if (dlg.exec() == QInputDialog::Accepted)
{
qDebug() << dlg.intValue();
}
- Enter the... Of the dialog box The input mode
- QInputDialog::TextInput Enter a text string
- QInputDialog::IntInput Input integer number
- QInputDialog::DoubleInput Enter floating point number
Code experiments
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
class Widget : public QWidget
{
Q_OBJECT
private:
QPushButton ColorDialogBtn;
QPushButton InputDialogBtn;
private slots:
void ColorDialogBtn_Clicked();
void InputDialogBtn_Clicked();
public:
Widget(QWidget *parent = 0);
~Widget();
};
#endif // WIDGET_H
#include "Widget.h"
#include <QDebug>
#include <QColorDialog>
#include <QInputDialog>
Widget::Widget(QWidget *parent)
: QWidget(parent), ColorDialogBtn(this), InputDialogBtn(this)
{
ColorDialogBtn.setText("Color Dialog");
ColorDialogBtn.move(20, 20);
ColorDialogBtn.resize(160, 30);
InputDialogBtn.setText("Input Dialog");
InputDialogBtn.move(20, 70);
InputDialogBtn.resize(160, 30);
resize(200, 120);
setFixedSize(200, 120);
connect(&ColorDialogBtn, SIGNAL(clicked()), this, SLOT(ColorDialogBtn_Clicked()));
connect(&InputDialogBtn, SIGNAL(clicked()), this, SLOT(InputDialogBtn_Clicked()));
}
Widget::~Widget()
{
}
void Widget::ColorDialogBtn_Clicked()
{
QColorDialog dlg(this);
dlg.setWindowTitle("Color Editor");
dlg.setCurrentColor(Qt::red);
if (dlg.exec() == QColorDialog::Accepted) {
QColor color = dlg.selectedColor();
qDebug() << color;
qDebug() << color.red();
qDebug() << color.green();
qDebug() << color.blue();
qDebug() << color.hue();
qDebug() << color.saturation();
qDebug() << color.value();
}
// Simple usage
QColor c = QColorDialog::getColor(Qt::red, this, "Color Edit");
qDebug() << c;
}
void Widget::InputDialogBtn_Clicked()
{
QInputDialog dlg(this);
dlg.setWindowTitle("Input Test");
dlg.setLabelText("Please input a string:");
dlg.setInputMode(QInputDialog::TextInput);
if (dlg.exec() == QInputDialog::Accepted) {
qDebug() << dlg.textValue();
}
// Simple usage
qDebug() << QInputDialog::getDouble(this, "Input double", "Please input double:");
qDebug() << QInputDialog::getInt(this, "Input int", "Please input int:");
QStringList ql;
QStringList items;
items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter");
bool ok;
QString item = QInputDialog::getItem(this, tr("QInputDialog::getItem()"),
tr("Season:"), items, 0, false, &ok);
qDebug() << item;
QString str = QInputDialog::getText(this, "getText", "Please input text:");
qDebug() << str;
}
#include "Widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
Summary
- QColorDialog Class is used to provide Dialog box parts with assigned colors
- QColor Class is used in programs to represent Color The concept of
- QInputDialog Class used Occasions requiring temporary data input
边栏推荐
- [ACNOI2022]猜数
- Unity Render Streaming通过Js与Unity自定义通讯
- Leetcode-1175.Prime Arrangements
- 顺序表(C语言实现)
- [bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
- 叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
- GoLand 2021.1.1: configure the multi line display of the tab of the open file
- NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
- 树的深入和广度优先遍历(不考虑二叉树)
- Go 1.16.4: manage third-party libraries with Mod
猜你喜欢
Flutter dynamic | fair 2.5.0 new version features
Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
Failure of vector insertion element iterator in STL
Universal dividend source code, supports the dividend of any B on the BSC
Mastering the cypress command line options is the basis for truly mastering cypress
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
可编程逻辑器件软件测试
Using registered classes to realize specific type matching function template
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
随机推荐
JVM系列——概述,程序计数器day1-1
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
How to promote the progress of project collaboration | community essay solicitation
PHP maze game
GoLand 2021.1: rename the go project
Implementation of Muduo asynchronous logging
Qt学习23 布局管理器(二)
Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
项目协作的进度如何推进| 社区征文
PhpMyAdmin stage file contains analysis traceability
Use vscode to view hex or UTF-8 codes
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
全局事件总线
SQL Injection (POST/Search)
Leetcode-1175. Prime Arrangements
Replace the GPU card number when pytorch loads the historical model, map_ Location settings
Unity render streaming communicates with unity through JS
The solution of Chinese font garbled code in keil5
Field problems in MySQL