1.一个QGroupBox 中添加QCheckBox,控制这个QGroupBox是否可用,当check为true时QGroupBox可用,反之不可用.group里有个限制1000以内的整形数的QLineEdit和一个QLabel
m_LineEditCustom = new QLineEdit; m_LineEditCustom->setValidator(new QIntValidator(1, 999, m_LineEditIterate)); m_GroupCustom = new QGroupBox(QString("输入初始值")); m_GroupCustom->setCheckable(true); m_GroupCustom->setChecked(false); QHBoxLayout* hLayout = new QHBoxLayout; hLayout->addWidget(new QLabel("输入值:")); hLayout->addWidget(m_LineEditCustom); m_GroupCustom->setLayout(hLayout);2.QComboBox添加选项Item
QStringList DrawTypeList; DrawTypeList.clear(); DrawTypeList.push_back(QString("第一个")); DrawTypeList.push_back(QString("第二个")); DrawTypeList.push_back(QString("第三个")); DrawTypeList.push_back(QString("第四个")); DrawTypeList.push_back(QString("第五个")); m_ComboBox->clear(); m_ComboBox->addItems(DrawTypeList);
3.QDialog桌面居中显示,this是QDialog类界面创建函数
QDesktopWidget *desktop = QApplication::desktop(); QRect deskRect = desktop->availableGeometry(); int x = (deskRect.width() - this->width())/2; int y = (deskRect.height() - this->height())/2; this->move(x, y); this->setFixedSize(450, 200); this->setAutoFillBackground(true); this->setWindowModality(Qt::ApplicationModal);4.QLineEdit显示密码形式
m_LineEditPWD->setEchoMode(QLineEdit::Password); m_LineEditPWD->setStyleSheet("lineedit-password-character: 42");5.QWidget添加背景图片
QPalette palette; palette.setBrush(this->backgroundRole(),QBrush(QImage(":/images/fmm.png"))); this->setPalette(palette); this->setAutoFillBackground(true); //添加登录框的logo. this->setWindowIcon(QIcon(":/images/logo.png"));6.QLabel设置QSS样式表
QLabel *nameLabel = new QLabel("账 户: ", layoutWidget); nameLabel->setStyleSheet(QString::fromUtf8("QLabel{color:#ffffff}"));
7.让一个对话框总是在所有的窗口的最前面显示
this->setWindowFlags(Qt::WindowStaysOnTopHint);
8.修改QMessageBox按钮的显示的文本,使用addButton函数;
QPushButton * QMessageBox::addButton ( const QString & text, ButtonRole role )
QPushButton * a = mesBox.addButton("A", QMessageBox::YesRole);