layout.cpp

来自「中嵌培训资料」· C++ 代码 · 共 50 行

CPP
50
字号
#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 + =
减小字号Ctrl + -
显示快捷键?