04-03.cpp

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

CPP
54
字号
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qlineedit.h>
#include <qslider.h>

class MyMainwindow : public QWidget
{
public:
	MyMainwindow();
private:
	QPushButton *b1;
	QPushButton *b2;
	QPushButton *b3;
	QLineEdit *ledit;
};

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

	b1 = new QPushButton("click here to mark the text", this);
	b1->setGeometry(10, 10, 280, 40);
	b1->setFont(QFont("Time", 18, QFont::Bold));

	b2 = new QPushButton("click here to unmark the text", this);
	b2->setGeometry(10, 60, 280, 40);
	b2->setFont(QFont("Time", 18, QFont::Bold));

	b3 = new QPushButton("click here to remove the text", this);
	b3->setGeometry(10, 110, 280, 40);
	b3->setFont(QFont("Time", 18, QFont::Bold));

	ledit = new QLineEdit("This is a line of text", this);
	ledit->setGeometry(10, 160, 280, 30);

	//
	//
	//
	connect(b1, SIGNAL(clicked()), ledit, SLOT(selectAll()));
	connect(b2, SIGNAL(clicked()), ledit, SLOT(deselect()));	
	connect(b3, SIGNAL(clicked()), ledit, SLOT(clear()));
}

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 + -
显示快捷键?