当前位置: 首页 > wzjs >正文

网站设计0基础中国十大seo

网站设计0基础,中国十大seo,网站开发用什么编辑器,安全教育平台QT的消息盒子和对话框(自定义对话框) 一、消息盒子QMessageBox1、弹出警告盒子示例代码:现象: 2、致命错误盒子示例代码:现象: 3、帮助盒子示例代码:现象: 4、示例代码: …

QT的消息盒子和对话框(自定义对话框)

  • 一、消息盒子QMessageBox
    • 1、弹出警告盒子
      • 示例代码:
      • 现象:
    • 2、致命错误盒子
      • 示例代码:
      • 现象:
    • 3、帮助盒子
      • 示例代码:
      • 现象:
    • 4、示例代码:
  • 二、QT中自带的对话框
    • 1、颜色对话框 QColorDialog
      • 1)方法
        • 示例代码:
        • 现象:
    • 2、字体对话框 QFontDialog
      • 1) 方法
        • 示例代码:
        • 现象:
    • 3、文件对话框 QFileDialog
      • 1) 方法:弹出文件对话框,让用户可以选择某个具体的文件
        • 示例代码:
        • 现象:
      • 2) 方法:弹出目录对话框,只能让用户选择目录,不可以选择目录中具体文件
        • 示例代码:
  • 三、自定义对话框
    • 1.模态和非模态
      • 示例代码:
      • 现象:

一、消息盒子QMessageBox

1、弹出警告盒子

[static] StandardButton QMessageBox::warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)返回值:点击了盒子里面的哪个按钮,返回值就返回这个按钮参数:parent --this,父窗口title --》消息盒子的标题text --》盒子里面的文本内容 buttons --》盒子默认使用哪些按钮,默认使用ok按钮如果要添加多个按钮,多个按钮之间使用 按位或 连接起来defaultButton --》当按下回车键,默认选中的按钮

示例代码:

QMessageBox::warning(this, "警告","您输入的账号或密码错误,请重新输入", QMessageBox::Close | QMessageBox::Ok, QMessageBox::Close);

现象:

在这里插入图片描述

2、致命错误盒子

[static] StandardButton QMessageBox::critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)
// 定义如警告盒子

示例代码:

QMessageBox::critical(this, "致命错误","您输入的账号或密码错误,请重新输入", QMessageBox::Close | QMessageBox::Ok, QMessageBox::Close);

现象:

在这里插入图片描述

3、帮助盒子

[static] StandardButton QMessageBox::question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons = StandardButtons( Yes | No ), StandardButton defaultButton = NoButton)
// 定义如警告盒子

示例代码:

QMessageBox::question(this, "帮助","您输入的账号或密码错误,请重新输入", QMessageBox::Close | QMessageBox::Ok, QMessageBox::Close);

现象:

在这里插入图片描述

  如何判断点击了哪个按钮
方法:通过warning函数的返回值判断,具体参见例子代码if(ret==QMessageBox::Ok){}else  //其他按钮{}

4、示例代码:

auto ret = QMessageBox::question(this, "帮助","您输入的账号或密码错误,请重新输入", QMessageBox::Close | QMessageBox::Ok, QMessageBox::Close);
if (ret == QMessageBox::Ok)
{// 按实际逻辑做处理qDebug()<<"点击的是ok";
}
else
{qDebug()<<"点击的是close";
}

二、QT中自带的对话框

1、颜色对话框 QColorDialog

1)方法

[static] QColor QColorDialog::getColor(const QColor &initial = Qt::white, QWidget *parent = Q_NULLPTR, const QString &title = QString())返回值:弹出的对话框所选中的颜色参数:initial --》颜色对话框默认选中的颜色//依据RGB的值新建颜色对象QColor(int r, int g, int b)   parent --》父窗口 thistitle --》颜色对话框的标题如何判断用户是否选中了某个颜色bool QColor::isValid() const返回值:如果用户点击ok  --》颜色就是合法,返回true反之,返回false
示例代码:
// mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void on_btn1_clicked();private:Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H// mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QColorDialog>
#include <QDebug>MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);
}MainWindow::~MainWindow()
{delete ui;
}// 颜色对话框
void MainWindow::on_btn1_clicked()
{QColor color1(0, 0, 255);// 弹出颜色对话框QColor color_ret = QColorDialog::getColor(color1, this, "颜色对话框");// 判断用户是点击了ok还是cancelif(color_ret.isValid()){qDebug()<<"点击了ok";// 拼接得到qss语句QString set_style = QString("background-color:rgb(%1,%2,%3);").arg(color_ret.red()).arg(color_ret.green()).arg(color_ret.blue());// 把按钮的背景色设置成自己选择的颜色ui->btn1->setStyleSheet(set_style);}else{qDebug()<<"点击了cancel";}
}
现象:

在这里插入图片描述

2、字体对话框 QFontDialog

1) 方法

[static] QFont QFontDialog::getFont(bool *ok, QWidget *parent = Q_NULLPTR)返回值:所选中的字体参数:ok --》保存是否选中了某个字体,选中了 --true  没有选中 --falseparent --》父窗口 this
如何判断用户是否选中了某个字体方法:判断getFont的第一个参数是否为真
QString QFont::family() const返回值:返回选中的字体名字
int QFont::pointSize() const 返回值:返回选中的字体大小
示例代码:
// mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void on_pushButton_clicked();private:Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H// mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFontDialog>
#include <QDebug>MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::on_pushButton_clicked()
{bool is_ok;QFont myFont = QFontDialog::getFont(&is_ok, this);if (is_ok){qDebug()<<"选择了ok";ui->label->setFont(myFont);}else{qDebug()<<"选择了concel";}
}
现象:

在这里插入图片描述

3、文件对话框 QFileDialog

1) 方法:弹出文件对话框,让用户可以选择某个具体的文件

[static] QString QFileDialog::getOpenFileName(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString())返回值:选中的某个文件的绝对路径名参数:parent --》父窗口 thiscaption --》文件对话框的标题dir --》指定要打开的目录路径filter --》文件过滤器,过滤掉不需要的文件比如: "*.txt"        表示只想查看文件夹中的记事本"*.txt *.bmp"  表示想查看文件夹中的记事本和bmp图片
示例代码:
// mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void on_pushButton_clicked();private:Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H// mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDebug>MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::on_pushButton_clicked()
{QString pathName = QFileDialog::getOpenFileName(this, "打开的文件对话框", "C:/Users/xxx/Desktop/vm_shared/code/QT_proj/250406_test", "*txt *xls");qDebug()<< "选择的文件是"<< pathName;
}
现象:

在这里插入图片描述

2) 方法:弹出目录对话框,只能让用户选择目录,不可以选择目录中具体文件

[static] QString QFileDialog::getExistingDirectory(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString())返回值:选中的某个目录的绝对路径名参数:parent --》父窗口 thiscaption --》目录对话框的标题dir --》指定要打开的目录路径
示例代码:
 // 打开目录对话框
QString dirPath = QFileDialog::getExistingDirectory(this, "目录");

三、自定义对话框

QT添加新的ui界面总共提供三种模板,三者区别
dialog --》作为独立的弹窗来使用
mainwindow --》多界面跳转,界面直接切换
widget --》作为子窗口来使用,嵌套到mainwindow

如何新建Qdialog:
右键点击工程名–》QT设计师界面类,选择QDialog模板

1.模态和非模态

          模态对话框 --》exec(),对话框如果不关闭,无法操作其他界面非模态对话框 --》show(),对话框如果不关闭,不影响操作其他界面

示例代码:

firstwin.h firstwin.cpp

// firstwin.h
#ifndef FIRSTWIN_H
#define FIRSTWIN_H#include <QMainWindow>QT_BEGIN_NAMESPACE
namespace Ui { class firstwin; }
QT_END_NAMESPACEclass firstwin : public QMainWindow
{Q_OBJECTpublic:firstwin(QWidget *parent = nullptr);~firstwin();private slots:void on_pushButton_clicked();void on_pushButton_2_clicked();private:Ui::firstwin *ui;
};
#endif // FIRSTWIN_H// firstwin.cpp
#include "firstwin.h"
#include "ui_firstwin.h"
#include <QDebug>
#include "secondwin.h"
#include "regdialog.h"
firstwin::firstwin(QWidget *parent): QMainWindow(parent), ui(new Ui::firstwin)
{ui->setupUi(this);
}firstwin::~firstwin()
{delete ui;
}//登录按钮的槽函数
void firstwin::on_pushButton_clicked()
{//获取输入的用户名和密码QString name=ui->lineEdit->text();QString passwd=ui->lineEdit_2->text();if(name=="hello" && passwd=="123456"){//跳到主界面--》第二个界面//创建第二个界面对象secondwin *win=new secondwin();//显示第二个界面win->show();//关闭第一个界面this->close();}elseqDebug()<<"登录失败";
}
//注册按钮对应的槽函数
void firstwin::on_pushButton_2_clicked()
{//弹出注册对话框regdialog *dialog=new regdialog(this);//显示对话框//dialog->show();  //非模态对话框dialog->exec();    //模态对话框
}

secondwin.cpp secondwin.h

// secondwin.h
#ifndef SECONDWIN_H
#define SECONDWIN_H#include <QMainWindow>namespace Ui {
class secondwin;
}class secondwin : public QMainWindow
{Q_OBJECTpublic:explicit secondwin(QWidget *parent = nullptr);~secondwin();private slots:void on_pushButton_clicked();void on_pushButton_2_clicked();private:Ui::secondwin *ui;
};#endif // SECONDWIN_H// secondwin.cpp
#include "secondwin.h"
#include "ui_secondwin.h"secondwin::secondwin(QWidget *parent) :QMainWindow(parent),ui(new Ui::secondwin)
{ui->setupUi(this);
}secondwin::~secondwin()
{delete ui;
}void secondwin::on_pushButton_clicked()
{//证明QWidget一般作为子窗口嵌套到QMainWindow里面ui->widget->hide();
}void secondwin::on_pushButton_2_clicked()
{//证明QWidget一般作为子窗口嵌套到QMainWindow里面ui->widget->show();
}

regdialog.h regdialog.cpp

// regdialog.h
#ifndef REGDIALOG_H
#define REGDIALOG_H#include <QDialog>namespace Ui {
class regdialog;
}class regdialog : public QDialog
{Q_OBJECTpublic:explicit regdialog(QWidget *parent = nullptr);~regdialog();private:Ui::regdialog *ui;
};#endif // REGDIALOG_H// regdialog.cpp
#include "regdialog.h"
#include "ui_regdialog.h"regdialog::regdialog(QWidget *parent) :QDialog(parent),ui(new Ui::regdialog)
{ui->setupUi(this);
}regdialog::~regdialog()
{delete ui;
}

现象:

在这里插入图片描述


文章转载自:

http://PAt1h6qp.cfybL.cn
http://qQkDBkHT.cfybL.cn
http://CscBxbdL.cfybL.cn
http://0O9swTCp.cfybL.cn
http://JpI3PbnP.cfybL.cn
http://DyAsbHYs.cfybL.cn
http://50q4zfDY.cfybL.cn
http://qyCAzAXB.cfybL.cn
http://DEaDkyrh.cfybL.cn
http://CfqQVVO5.cfybL.cn
http://kfTFOqC1.cfybL.cn
http://1MZxj3Es.cfybL.cn
http://fxHrrcvW.cfybL.cn
http://zYjFMRvq.cfybL.cn
http://PGsFjIhY.cfybL.cn
http://dxFwsJ7O.cfybL.cn
http://HUl8S6Or.cfybL.cn
http://8bPSB4HG.cfybL.cn
http://w9mZmpfh.cfybL.cn
http://fDHvx8TN.cfybL.cn
http://8PW6XflT.cfybL.cn
http://LCnyUaly.cfybL.cn
http://hiiPbVn9.cfybL.cn
http://3cnzcBDh.cfybL.cn
http://CQGZAW50.cfybL.cn
http://JiNYDzAf.cfybL.cn
http://UlD8i0mh.cfybL.cn
http://8OzuQDKM.cfybL.cn
http://8YM9cldS.cfybL.cn
http://Ee31z5qR.cfybL.cn
http://www.dtcms.com/wzjs/620722.html

相关文章:

  • 购物网站建设包括哪些深圳人才大市场官网招聘信息
  • 字体设计网站有哪些免费网站专题页面制作
  • 建设网站的公司swot梅州建站公司
  • 民治营销型网站费用18岁可以注册cn域名吗
  • 网站开发语言比较网站建设培训目标
  • 上海建设安全生产协会网站台州卓远做网站好不好
  • 简洁大方的网站首页南通企业建站系统模板
  • 阿里云网站建设方案书wordpress分类描述
  • 莒南县建设局网站wordpress会员充值
  • 前端可以做网站吗上海传媒公司李闪闪身价
  • 做公司网站按年收费建立一个网站的英文
  • 东兴移动网站建设wordpress 防注入
  • 简单制作网站的过程工商局网站建设方案
  • 个人网站可以做商业吗重庆排名seo公司
  • 网站制作公司北京网站建设公司计算机网络实验 做网站的
  • 广州市白云区网站建设企业网站做seo
  • wordpress header在哪如何做网站导航栏的搜索引擎优化
  • php小型网站开发网页app
  • 镇江优化九一景德镇seo
  • 化州网站开发公司wordpress读不出媒体库
  • 大连网站设计开发网站开发外包 价格
  • 自己可以做门户网站吗网址自动生成手机网站
  • 单页网站上传教程网站动态页面怎么做
  • 文本编辑器 网站python浪漫星空代码
  • js做网站跳转wordpress类目
  • wordpress建站 app访问太原中小企业网站制作
  • 大港建站公司清河做网站哪儿好
  • 凡科建的网站怎么做seo深圳企业网站建设设计公司
  • 北京开发网站自贡建设专业网站设计
  • 做外包哪个网站好一些文老师网络规划设计师