📄 layout.cpp
字号:
#include <qapplication.h>#include <qlabel.h>#include <qpushbutton.h>#include <qlayout.h>class DemoWidget:public QWidget{public: DemoWidget( QWidget *parent=0, const char *name=0);};DemoWidget::DemoWidget( QWidget *parent, const char *name):QWidget(parent, name){ setCaption("QT_LAYOUT_DEMO"); QBoxLayout *demoLayout = new QVBoxLayout (this, 5); QBoxLayout *buttons = new QHBoxLayout(demoLayout); int i; for (i=1; i<=4; i++) { QPushButton *btn = new QPushButton(this); QString s; s.sprintf( "Button %d", i ); btn->setText(s); buttons->addWidget( btn, 10 ); } QLabel *lbl = new QLabel(this); lbl->setText("This is a Label"); lbl->setFrameStyle( QFrame::Panel | QFrame::Sunken ); lbl->setFixedHeight( lbl->sizeHint().height() ); lbl->setAlignment( AlignVCenter | AlignLeft); demoLayout->addWidget(lbl); demoLayout->activate();}int main(int argc, char **argv){ QApplication app(argc, argv); DemoWidget demo; app.setMainWidget(&demo); demo.show(); return app.exec();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -