1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <QApplication> #include <QWidget> #include <QLabel> #include <QVBoxLayout>
void testLabelVariety(QWidget *parent) { QVBoxLayout *layout = new QVBoxLayout(parent);
QLabel *txtLabel = new QLabel("这是一段普通的文字"); QLabel *styleLabel = new QLabel(); styleLabel->setText("<b>加粗文字</b> <i style='color:blue;'>蓝色斜体</i>"); QLabel *imgLabel = new QLabel(parent); imgLabel->setPixmap(QPixmap(":/logo.png")); imgLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
layout->addWidget(txtLabel); layout->addWidget(styleLabel); layout->addWidget(imgLabel); layout->addStretch(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv);
QWidget w; w.setWindowTitle("Label测试"); w.resize(400, 300);
testLabelVariety(&w);
w.show(); return a.exec(); }
|