资源描述:
《Qt 设置对话框中按钮》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Qt对话框及其按钮本文应该说主要是讲述Qt按钮的一些设置方法,主要内容为:标准按钮的创建、自设按钮、按钮文本的中英文显示、按钮的禁用、设置按钮大小、按钮的透明设置、默认按钮、按钮上图标加载、对话框上显示中英文文本、对话框标题等。程序中已给出解释:首先:.h文件#ifndefMESSAGEBOX_H#defineMESSAGEBOX_H#includeclassQLabel;classMessageBox:publicQDialog{Q_OBJECTpublic:MessageBox(QWidget*parent=0);pub
2、licslots:voidslotQuestion();voidslotInformation();voidslotWarning();voidslotCritical();voidslotAbout();voidslotAboutQt();voidslotCustom();private:QLabel*label;};#endif//MESSAGEBOX_H其次:.cpp文件#include"messagebox.h"#includeMessageBox::MessageBox(QWidget*parent):QDialog(
3、parent){setWindowTitle(trUtf8("345257271350257235346241206345255246344271240347244272344276213"));label=newQLabel;QPushButton*btn1=newQPushButton(this);btn1->setText(trUtf8("347226221351227256"));//显示按钮中文名称QPushButton*btn2=newQPushButton("this");b
4、tn2->setText(trUtf8("344277241346201257"));QPushButton*btn3=newQPushButton("this");btn3->setText(trUtf8("346217220351206222"));QPushButton*btn4=newQPushButton("Critical");//按钮名称为英文QPushButton*btn5=newQPushButton("About");QPushButton*btn6=newQPushButton("AboutQt"
5、);QPushButton*btn7=newQPushButton("Custom");QGridLayout*grid=newQGridLayout;grid->addWidget(btn1,0,0);grid->addWidget(btn2,0,1);grid->addWidget(btn3,1,0);grid->addWidget(btn4,1,1);grid->addWidget(btn5,2,0);grid->addWidget(btn6,2,1);grid->addWidget(btn7,3,0);QVBoxLayout*main
6、Layout=newQVBoxLayout;mainLayout->setMargin(10);mainLayout->setSpacing(20);mainLayout->addWidget(label);mainLayout->addLayout(grid);setLayout(mainLayout);connect(btn1,SIGNAL(clicked()),this,SLOT(slotQuestion()));connect(btn2,SIGNAL(clicked()),this,SLOT(slotInformation()));c
7、onnect(btn3,SIGNAL(clicked()),this,SLOT(slotWarning()));connect(btn4,SIGNAL(clicked()),this,SLOT(slotCritical()));connect(btn5,SIGNAL(clicked()),this,SLOT(slotAbout()));connect(btn6,SIGNAL(clicked()),this,SLOT(slotAboutQt()));connect(btn7,SIGNAL(clicked()),this,SLOT(slotCus
8、tom()));}voidMessageBox::slotCustom(){QMessageBoxcustomMsgBox;customMsgBox.setWind