QFileDialog:文件对话框
QString fileName=QFileDialog::getOpenFileName(this,"打开文件", "/", "文本文件(*.txt);;C文件(*.c);;json文件(*.json)");
QColorDialog:颜色对话框
QColor c=QColorDialog::getColor(QT::blue);
QFontDialog:字体对话框
bool ok; QFont f=QFontDialog::getFont(&ok);
QInputDialog:输入对话框
//文本输入 QString text=QInputDialog::getText(this, "字符串对话框", "请输入姓名:", QLineEdit::Normal, "默认值", &ok);//ok==true,点击了确定按钮,false,点击了取消按钮 //列表选择 QStringList listItem; listItem<<"A"<<"B"; QString item=QInputDialog::getItem(this, "选择对话框", "请选择:", listItem, 0, false, &ok); //int输入 int age=QInputDialog::getInt(this, "int输入对话框", "请输入年龄:", 20, 0, 100, 1, &ok); //double输入 double score=QInputDialog::getInt(this, "int输入对话框", "请输入成绩:", 80, 0, 100, 1, &ok);
QMessageBox:消息对话框,包括Question, Information, Warning, Critical, About, Custom
QMessageBox::question(this, "Question消息框", "是否退出程序?", QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Ok); QMessageBox::information(this, "Information消息框", "欢迎来到三体世界"); QMessageBox::warning(this, "Warning消息框", "是否退出程序?", QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Ok); QMessageBox::critical(this, "Critical消息框", "欢迎来到三体世界"); QMessageBox::about(this, "About消息框", "欢迎来到三体世界");
QToolBox:工具盒类(类似QQ)
进度条有两种:QProgressBar,QProgressDialog
QPalette:调色板
QTime
QTime time=QTime::currentTime(); QString str=time.toString("hh:mm:ss");
可扩展对话框
不规则窗体
程序启动画面
#include "mainwindow.h" #include <QApplication> #include <QPixmap> #include <QSplashScreen> int main(int argc, char *argv[]) { QApplication a(argc, argv); QPixmap pixmap("Qt.png"); //(a) QSplashScreen splash(pixmap); //(b) splash.show(); //显示此启动图片 a.processEvents(); //(c) MainWindow w; w.show(); splash.finish(&w); //(e) return a.exec(); }