Qt学习笔记之QLabel、QLineEdit控件

来源:互联网 发布:淘宝订单留言在哪里 编辑:程序博客网 时间:2024/05/01 22:34
  • QLabel 标签:在窗体中创建 QLabel 标签显示“我是 QLabel”字样,红色加粗倾斜字体。
#include <QApplication>#include <QLabel>int main(int argc, char *argv[]){    QApplication a(argc, argv);    QLabel *label;    //实例 QLabel 控件    label = new QLabel();    label->setText("我是 QLabel");    //QLabel 位置    //label->move(100,100);    label->setGeometry(QRect(100,100,200,30));    //label 样式(CSS 样式表)    //font-size 字号    //color 字体颜色    //font-weight 字宽    //font-style 字体样式    label->setStyleSheet("font-size:20px;color:red;font-weight:bold;font-style:italic");    label->show();    return a.exec();}
  • QLineEdit 单行文本:将输入的文字变成密码显示的形式
#include <QApplication>#include <QLineEdit>int main(int argc, char *argv[]){    QApplication a(argc, argv);    QLineEdit *lineEdit;    //创建 QLineEdit 控件    lineEdit = new QLineEdit();    //位置大小    lineEdit->setGeometry(QRect(100,100,200,25));    //样式    //border 边框线大小    //border-style 边框样式 solid 实线    //border-color:blue red 上下蓝色 左右红色    lineEdit->setStyleSheet("border:1px;border-style:solid;color:red;border-color: bluered;");    //限制最长输入 12 位    lineEdit->setMaxLength(12);    //不可写入    //lineEdit->setEchoMode(QLineEdit::NoEcho);    //密码*号输入    lineEdit->setEchoMode(QLineEdit::Password);    lineEdit->show();    return a.exec();}
原创粉丝点击