日期:2014-05-16 浏览次数:20706 次
#include <QT/QApplication.h> #include <QT/QPushButton.h> #include <QT/QTextEdit.h> #include <string> class MyWidget : public QWidget { private: QTextEdit *pText1,*pText2; QPushButton *pButton; public: MyWidget(QWidget* parent); ~MyWidget(); public slots: void buttonPressed(); }; MyWidget::MyWidget(QWidget* parent) :QWidget(parent) { setFixedSize(300,300); pText1 = new QTextEdit("Edit1",this); pText2 = new QTextEdit("Edit2",this); pButton = new QPushButton("Button",this); pText1->resize(100,100); pText1->setGeometry(0,0,100,100); pText2->resize(100,100); pText2->setGeometry(120,0,100,100); pButton->resize(100,30); pButton->setGeometry(10,200,100,30); QObject::connect(pButton,SIGNAL(clicked()),this,SLOT(buttonPressed())); } MyWidget::~MyWidget() { delete pText1; delete pText2; delete pButton; } void MyWidget::buttonPressed() { pText2->setText(pText1->toPlainText()); } int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.resize(400,400); MyWidget my_widget(&window); my_widget.setGeometry(10,10,300,300); window.show(); return app.exec(); }