- QLabel 标签:在窗体中创建 QLabel 标签显示“我是 QLabel”字样,红色加粗倾斜字体。
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel *label;
label = new QLabel();
label->setText("我是 QLabel");
label->setGeometry(QRect(100,100,200,30));
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;
lineEdit = new QLineEdit();
lineEdit->setGeometry(QRect(100,100,200,25));
lineEdit->setStyleSheet("border:1px;border-style:solid;color:red;border-color: bluered;");
lineEdit->setMaxLength(12);
lineEdit->setEchoMode(QLineEdit::Password);
lineEdit->show();
return a.exec();
}