03-04.cpp

来自「qt实例代码!《24小时学通qt编程》 的代码!不错!已经在qt2.3.7调试o」· C++ 代码 · 共 42 行

CPP
42
字号
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include <qfont.h>
//
//
#include <qlabel.h>

class MyMainwindow : public QWidget
{
public:
	MyMainwindow();
private:
	QPushButton *b1;
	QLabel *label;
};

MyMainwindow::MyMainwindow()
{
	setGeometry(100, 100, 200, 120);

	b1 = new QPushButton("Buttom 1", this);
	b1->setGeometry(20, 20, 160, 80);
	b1->setFont(QFont("Time", 18, QFont::Bold));

	//
	//
	label = new QLabel(this);
	label->setGeometry(20, 110, 160, 50);
	label->setText("This is the first line\n \
		This is the second line");
	label->setAlignment(AlignCenter);
}

int main(int argc, char **argv)
{
	QApplication a(argc,argv);
	MyMainwindow w;
	a.setMainWidget(&w);
	w.show();
	a.exec();
}	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?