QT学习

1.按键的用法

QPushButton button;
    button.setText("button");
    button.setParent(&w);
    button.show();
    //按键界面产生关联
    QObject::connect(&button,SIGNAL(clicked()),&w,SLOT(close()));
    button.setGeometry(30,30,100,30);//设置位置和大小

2.编辑框的用法

/*
    QLineEdit edit;
    edit.setParent(&w);
    edit.show();
    */
    /*
    edit.setEchoMode(QLineEdit::Password);//设置为密码形式
    edit.setPlaceholderText("please input passwd");//设置提示
    edit.text();//接收输入的内容,还不会显示出来
     */
    /*
    QCompleter completer(QStringList()<<"123"<<"abc"<<"987");//设置提示内容
    completer.setFilterMode(Qt::MatchContains);//设置模式
    edit.setCompleter(&completer);//设置提示
     */

3.layout的用法

QPushButton button;
    button.setText("button");
    //button.show();//show()函数也可以不写
    QLineEdit edit;
    //edit.show();

#if 0
    QHBoxLayout layout;
    layout.addStretch(1);//增加弹簧  里面是比例
    layout.addWidget(&button);//将button定在layout内,可以加比例
    layout.addWidget(&edit,1);//layout会自动设置button,edit的父类,
                               //这里可不用再下写setparent()
    layout.addStretch(1);
    w.setLayout(&layout);//将layout定在w内
#endif

#if 0
    QGridLayout layout;
    layout.setColumnStretch(0,1);
    layout.setRowStretch(0,1);
    layout.setColumnStretch(3,1);
    layout.setRowStretch(3,1);
    layout.addWidget(&button,1,1);
    layout.addWidget(&edit,1,2);
    layout.addWidget(new QPushButton("aa"),2,1);
    layout.addWidget(new QPushButton("bb"),2,2);
#endif

#if 1
    QGridLayout layout;
    layout.setColumnStretch(0,1);
    layout.setRowStretch(0,1);
    layout.setColumnStretch(3,1);
    layout.setRowStretch(4,1);
    QLineEdit *passwd;
    layout.addWidget(new QLabel("username"),1,1);
    layout.addWidget(new QLineEdit(),1,2);
    layout.addWidget(new QLabel("passwordd"),2,1);
    layout.addWidget(passwd=new QLineEdit(),2,2);
    QHBoxLayout *BOX;
    layout.addLayout(BOX = new QHBoxLayout(),3,2);
    BOX->addStretch(1);
    BOX->addWidget(new QPushButton("login"));
    passwd->setEchoMode(QLineEdit::Password);
    w.setLayout(&layout);//将layout定在w内
#endif

4.标准对话框
1.QFileDialog

QString s = QFileDialog::getOpenFileName(
            this,
            "Open this dialog",
            "/",
            "C++ file(* .cpp)"
            );
qDebug()<

2.QColorDialog

 QColor color = QColorDialog::getColor();
 if(color.isValid())
 {
     int r,g,b;
     color.getRgb(&r,&g,&b);
     qDebug()<

3.QFontDialog

 bool ok;
QFont font = QFontDialog::getFont(&ok);
if(ok)
{
   btn2->setFont(font);
}

4.QMessageBox

information ,warning, question ,critical , about

QMessageBox::information(this,"title","content",QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes);

你可能感兴趣的:(QT学习)