新聞中心

QT helloworld 程序

作者: 時(shí)間:2016-12-01 來源:網(wǎng)絡(luò) 收藏

7、標(biāo)準(zhǔn)對(duì)話框

標(biāo)準(zhǔn)的文件對(duì)話框(QFileDialog)、標(biāo)準(zhǔn)的顏色對(duì)話框(QColorDialog)、標(biāo)準(zhǔn)的字體對(duì)話框(QFontDialog)

建立standardDialog GUI工程 Dialog窗口

三個(gè)pushbutton一個(gè)lineEdit一個(gè)Frame一個(gè)lineEdit

頭文件:文件對(duì)話框(QFileDialog、QSring)、字體對(duì)話框(QFont、QFontDialog)

顏色對(duì)話框(QColor、QColorDialog、QPalete)

#include

#include

#include

#include

#include

#include

#include

對(duì)應(yīng)的.cpp代碼

文件:注意QFileDialog::getOpenFileName()、setText(s.toAscii())

QStrings=QFileDialog::getOpenFileName(this, "Open File Dialog","/", "C++ files(*.cpp);;Headfiles(*.h)");

ui->txtFile->setText(s.toAscii());

字體:注意QFontDialog:getFont(&ok)、setFont(font)

bool ok;

QFontfont = QFontDialog::getFont(&ok);

if(ok)

{

ui->txtFont->setFont(font);

}

顏色:注意QColorDialog::getColor(Qt::blue)、setAutoFillBackground(true)、setPalette(QPalette(color))

QColorcolor = QColorDialog::getColor(Qt::blue);

if(color.isValid())

{

ui->frmColor->setAutoFillBackground(true);

ui->frmColor->setPalette(QPalette(color));

}

8、標(biāo)準(zhǔn)輸入框

多文本

QInputDialog::getText(this,"inputuser name!","Please input user name:", QLineEdit::Normal,nameLabel->text(),&ok);

txtName->setText(s.toAscii());

有限文本

QInputDialog::getItem(this,"Input***!", "Please select the ***:",list, 0,false,&ok);

ui->txtSex->setText(s.toAscii());

整數(shù)輸入

QInputDialog::getInteger(this,"Input the Age!","Please input theage:",ageLabel->text().toInt(),0,150,1,&ok);

ui->txtAge->setText(QString(tr("%1")).arg(age));

實(shí)數(shù)輸入

QInputDialog::getDouble(this,"Input the height!","Please input theheight:",175,0,230,1,&ok);

ui->txtHeight->setText(QString(tr("%1")).arg(height));

8、標(biāo)準(zhǔn)消息框

消息:提問(question)、信息(information)、警告(warning)、致命提示(critical)

頭文件:QMessageBox

#include

.cpp文件

Int ret;

Ret=QMessageBox::question()

Ret=QMessageBox::information()

Ret=QMessgeBox::warning();

Ret=QmerssageBox::critical();


上一頁(yè) 1 2 下一頁(yè)

評(píng)論


技術(shù)專區(qū)

關(guān)閉