Qt常用窗體

QT自帶的窗體使用.


相關類 靜態函數 函數說明
QMessageBox QMessageBox::question question 消息框
QMessageBox QMessageBox::information information 消息框
QMessageBox QMessageBox::warning warning 消息框
QMessageBox QMessageBox::critical critical 消息框
QMessageBox QMessageBox::about about 消息框
QMessageBox QMessageBox::abouutQt abouut Qt 消息框

用例

QMessageBox::warning

1
2
3
4
int ret = QMessageBox::warning(this, tr("請看題"),   //標題
                                        tr("吃飯不?"),         //提示內容
                                        QMessageBox::Yes | QMessageBox::No //選擇內容
                                        | QMessageBox::Cancel);


相關類 靜態函數 函數說明
QFileDialog getOpenFileName() 獲得用戶選擇的文件名
QFileDialog getSaveFileName() 獲得用戶保存的文件名
QFileDialog getExistingDirectory() 獲得用戶選擇的已存在的目錄名
QFileDialog getOpenFileNames() 獲得用戶選擇的文件名列表

用例

getOpenFileNames

QString fileName = QFileDialog::getOpenFileName(this, //父類的指針 tr("Open File"), //打開窗口的標題 "/home/bbigq", //打開默認路徑 tr("Images (*.png *.xpm *.jpeg *.bmp)") //文件過濾器 這裏只能打開*.png *.xpm *.jpg );

 

getOpenFileNames() //獲得用戶選擇的文件名列表

QStringList temp = QFileDialog::getOpenFileNames( this, //父類的指針 "Select one or more files to open", //打開窗口的標題 "/home/bbigq/workspace/QT", //獲取的路徑 "Anyfile (*)"); //獲取所有文件 

 


相關類 靜態函數 函數說明
QColorDialog getColor() 獲得用戶選擇的顏色值

用例

getColor()

QColor color = QColorDialog::getColor(); //獲取顏色 QString choise_color = QString("color: %1;").arg(color.name()); //拼接顏色信息,將顏色信息填入choise_color中 ui->label->setStyleSheet(choise_color); //設置字體顏色

 

相關類 靜態函數 函數說明
QFontDialog getFont() 獲得用戶選擇的字體

用例

getFont()

QFont font = QFontDialog::getFont();//獲取字體

 

我的GITHUB

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章