我的源代码是
实现文件
- C/C++ code
#include <QtGui>#include "MyMainWindow.h"// place your code hereMyMainWindow::MyMainWindow(){ textEdit = new QTextEdit; friendView = new QTreeView; messageView = new QTextBrowser; QVBoxLayout *rightLayout = new QVBoxLayout; rightLayout->addWidget(messageView); rightLayout->addWidget(textEdit); QVBoxLayout *leftLayout = new QVBoxLayout; leftLayout->addWidget(friendView); QHBoxLayout *mainLayout = new QHBoxLayout ; mainLayout->addLayout(leftLayout); mainLayout->addLayout(rightLayout); setLayout(mainLayout); createActions(); createMenus();}void MyMainWindow::createActions(){ exitAction = new QAction(tr("E&xit"), this); exitAction->setShortcut(tr("Ctrl+Q")); exitAction->setStatusTip(tr("Exit the application")); connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));}void MyMainWindow::createMenus(){ fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(exitAction);}
头文件
- C/C++ code
#ifndef __MYMAINWINDOW_H__#define __MYMAINWINDOW_H__// place your code here#include <QMainWindow>class QAction; class QTextEdit;class QTextBrowser;class QTreeView;class QVBoxLayout;class QHBoxLayout;class MyMainWindow : public QMainWindow{ Q_OBJECTpublic: MyMainWindow();private: void createActions(); void createMenus(); QMenu *fileMenu; QAction *exitAction; QTextEdit *textEdit; QTextBrowser *messageView; QTreeView *friendView; };
主文件
- C/C++ code
#include <QApplication>#include "MyMainWindow.h"int main(int argc, char *argv[]){ QApplication app(argc, argv); MyMainWindow mainWin; mainWin.show(); return app.exec();}
运行之后,看不到
QTextEdit *textEdit;
QTextBrowser *messageView;
QTreeView *friendView;
------解决方案--------------------
使用setSizePolicy解决。
------解决方案--------------------