-
UID:102447
-
- 注册时间2010-08-02
- 最后登录2011-05-29
- 在线时间21小时
-
- 发帖16
- 搜Ta的帖子
- 精华0
- 金钱160
- 威望26
- 贡献值0
- 好评度16
-
访问TA的空间加好友用道具
|
Qt Creator中用QTextEdit类实现内置滚动条时,在 文本区域一直按回车键可以出现竖直滚动条,但是添加文本后只会换行而不能实现水平滚动?我的 C++源代码如下: - #include<qapplication.h>
- #include<qpushbutton.h>
- #include<qfont.h>
- #include<qwidget.h>
- #include<qscrollarea.h>
- #include<qtextedit.h>
- //we base our new class on QScrollArea instead of QWidget:
- class MyMainWindow:public QScrollArea
- {
- public:
- MyMainWindow();
- private:
- //we create a QWidget Object as a child widget to the QScrollArea Object instead:
- QWidget *main;
- QPushButton *b1;
- QPushButton *b2;
- QPushButton *b3;
- QPushButton *b4;
- QPushButton *b5;
- QTextEdit *edit1;
- };
- MyMainWindow::MyMainWindow()
- {
- //set the geometry for the scrollarea:
- setGeometry(100,100,470,410);
- main=new QWidget(this);
- main->resize(460,400);
- b1=new QPushButton("New",main);
- b1->setGeometry(10,10,80,30);
- b1->setFont(QFont("Times",18,QFont::Bold));
- b2=new QPushButton("Open",main);
- b2->setGeometry(100,10,80,30);
- b2->setFont(QFont("Times",18,QFont::Bold));
- b3=new QPushButton("Save",main);
- b3->setGeometry(190,10,80,30);
- b3->setFont(QFont("Times",18,QFont::Bold));
- b4=new QPushButton("Print",main);
- b4->setGeometry(280,10,80,30);
- b4->setFont(QFont("Times",18,QFont::Bold));
- b5=new QPushButton("Quit",main);
- b5->setGeometry(370,10,80,30);
- b5->setFont(QFont("Times",18,QFont::Bold));
- edit1=new QTextEdit(main);
- edit1->setGeometry(0,50,440,340);
- edit1->setText("Let's pretend this is a text editor.");
- //we must call the QScrollArea::setWidget function for each of its
- //child widgets. Since main holds all our other widgets,we only
- //have to insert that one:
- setWidget(main);
- }
- void main(int argc,char **argv)
- {
- QApplication a(argc,argv);
- MyMainWindow w;
- a.setActiveWindow(&w);
- w.show();
- a.exec();
- }
-
初学,还请大家能帮忙指教!非常感谢!
|