Qt5基本对话框学习
来源:互联网 发布:淘宝物流宝平台 编辑:程序博客网 时间:2024/05/18 13:43
书籍:《Qt5开发及实例》(第二版) 陆文周
1.标准颜色对话框类
colorBtn=new QPushButton; //创建各个控件的对象colorBtn->setText(QString::fromLocal8Bit ("颜色标准对话框实例"));colorFrame=new QFrame;colorFrame->setFrameShape(QFrame::Box);colorFrame->setAutoFillBackground(true);mainLayout->addWidget(colorBtn,1,0); //布局设计mainLayout->addWidget(colorFrame,1,1);connect(colorBtn,SIGNAL(clicked()),this,SLOT(showColor())); //事件关联
当setAutoFillBackground为false时, 不能正常取色
QFrame类可参考http://www.kuqin.com/qtdocument/qframe.html#details
槽函数感觉c一直都是valid,去掉if也没啥问题
void Dialog::showColor(){ QColor c = QColorDialog::getColor(Qt::blue); if(c.isValid()) { colorFrame->setPalette(QPalette(c)); }}
2.标准字体对话框类
void Dialog::showFont(){ bool ok; QFont f = QFontDialog::getFont(&ok); if (ok) { fontLineEdit->setFont(f); }}
设置字体的槽函数,之前一直有些转不过来为什么要bool ok;
发现书上就有解释,之前一直没仔细看:
若用户选择“OK”,则该参数*ok将设为true,函数返回用户所选择的字体;
否则,将设为false,函数返回默认字体
好像挺简单的一个点,之前怎么不能自己理解..平时bool用的太少了
3.自定义消息框
void Dialog::showCustomDlg(){ label->setText(tr("Custom Message Box")); QMessageBox customMsgBox; customMsgBox.setWindowTitle(QString::fromLocal8Bit ("用户自定义消息框")); //设置消息框的标题 QPushButton *yesBtn=customMsgBox.addButton(tr("Yes"),QMessageBox::ActionRole); QPushButton *noBtn=customMsgBox.addButton(tr("No"),QMessageBox::ActionRole); QPushButton *cancelBtn=customMsgBox.addButton(QMessageBox::Cancel); customMsgBox.setText(QString::fromLocal8Bit ("这是一个用户自定义消息框!")); customMsgBox.setIconPixmap(QPixmap("Qt.png")); customMsgBox.exec(); if(customMsgBox.clickedButton()==yesBtn) label->setText("Custom Message Box/Yes"); if(customMsgBox.clickedButton()==noBtn) label->setText("Custom Message Box/No"); if(customMsgBox.clickedButton()==cancelBtn) label->setText("Custom Message Box/Cancel"); return;}
QMessageBox为一个可以直接用的标准对话框
customMsgBox.setIconPixmap(QPixmap(“Qt.png”));
是一个插入图片的操作,应将图片放入build后的debug目录下
阅读全文
0 0
- Qt5基本对话框学习
- QT5 学习之路04---QT5基本对话框1
- QT5 学习之路05---QT5基本对话框2
- QT5 学习之路06---QT5基本对话框3
- Qt5基本对话框
- Qt5开发学习之Qt基本对话框(四)
- QT5基本对话框 标准颜色对话框
- Qt5.9基本登录对话框制作
- QT5 学习之路17---对话框简介
- QT5 学习之路21---文件对话框
- 《Qt5学习笔记5》创建对话框
- QT5 学习之路18---对话框数据传递
- QT5 学习之路20---标准对话框 QMessageBox
- Qt5基础(三)Qt登录对话框学习笔记
- QT学习 第一章:基本对话框--基本对话框使用
- QT5(6)对话框
- QT5 标准文件对话框
- QT5 标准字体对话框
- 将数据写入SD卡
- Bryce1010 Acm模板
- linux mint 使用软件管理器安装软件
- Java之多线程(2)--基础开篇
- Libevent-2.1.8源码分析——event_base(一)
- Qt5基本对话框学习
- 数据库的优化
- 剑指offer—旋转数组的最小数字
- node.js下mongoose简单操作实例
- Gym
- 关于阅读第一篇国外关于视觉论文的感受和收获
- 在线编辑器学习-xhEditor
- 2017-18赛季的湖人队会有怎样的面貌?
- Angular实现购物车