1.0

MainWindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include<QMainWindow>
#include<QAction>
#include<QMenu>
#include<QTextBrowser> class MainWindow : public QMainWindow{
Q_OBJECT
public:
MainWindow(); private slots:
void fNew();
void fClose(); private:
void SetupMenus();
void SetupEditor(); QTextBrowser *edit; QAction *newAction;
QAction *closeAction;
QMenu *file;
}; #endif // MAINWINDOW_H

MainWindow.CPP

#include<QtGui>
#include"MainWindow.h" MainWindow::MainWindow(){
QWidget *widget=new QWidget;
setCentralWidget(widget); /*QWidget *topfiller=new QWidget;
topfiller->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); QWidget *bottomFiller=new QWidget;
bottomFiller->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);*/ SetupEditor(); QVBoxLayout *layout=new QVBoxLayout;
/*layout->addWidget(topFiller);
layout->addWidget(bottomFiller);*/
layout->addWidget(edit);
widget->setLayout(layout); widget->setLayout(layout); SetupMenus(); setWindowTitle(tr("Main Window"));
setMinimumSize(256,256);
resize(512,480); } void MainWindow::SetupMenus(){
newAction=new QAction(tr("&New"),this);
newAction->setShortcut(QKeySequence::New);
connect(newAction,SIGNAL(triggered()),this,SLOT(fNew())); closeAction=new QAction(tr("E&xit"),this);
closeAction->setShortcut(QKeySequence::Close);
connect(closeAction,SIGNAL(triggered()),this,SLOT(fClose())); file=menuBar()->addMenu(tr("&File"));
file->addAction(newAction);
file->addAction(closeAction);
} void MainWindow::fNew(){
edit->clear();
} void MainWindow::fClose(){
this->close();
} void MainWindow::SetupEditor(){
edit=new QTextBrowser;
edit->setAcceptRichText(true);
edit->setAutoFormatting(QTextBrowser::AutoNone);
edit->setCursorWidth(1);
edit->setDocumentTitle(tr("new Document"));
edit->setCursorWidth(16);
edit->setReadOnly(false);
edit->setEnabled(true);
}

Main.CPP

#include<QApplication>
#include"MainWindow.h" int main(int argc,char* argv[]){
QApplication app(argc,argv);
MainWindow wnd;
wnd.show();
app.exec(); }

2.0

MainWindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include<QMainWindow>
#include<QAction>
#include<QMenu>
#include<QTextBrowser>
#include<QPushButton> class QHBoxLayout;
class MainWindow : public QMainWindow{
Q_OBJECT
public:
MainWindow(); private slots:
void fNew();
void fClose(); private:
void SetupMenus();
void SetupEditor(); QTextBrowser *edit;
QPushButton *newBtn;
QPushButton *exit; QAction *newAction;
QAction *closeAction;
QMenu *file;
QHBoxLayout *btnBox;
}; #endif // MAINWINDOW_H

MainWindow.CPP

#include<QtGui>
#include"MainWindow.h" MainWindow::MainWindow(){
QWidget *widget=new QWidget;
setCentralWidget(widget); SetupEditor(); QVBoxLayout *layout=new QVBoxLayout;
layout->addLayout(btnBox);
layout->addWidget(edit);
widget->setLayout(layout); widget->setLayout(layout); SetupMenus(); setWindowTitle(tr("Main Window"));
setMinimumSize(256,256);
resize(512,480); } void MainWindow::SetupMenus(){
newAction=new QAction(tr("&New"),this);
newAction->setShortcut(QKeySequence::New);
connect(newAction,SIGNAL(triggered()),this,SLOT(fNew())); closeAction=new QAction(tr("E&xit"),this);
closeAction->setShortcut(QKeySequence::Close);
connect(closeAction,SIGNAL(triggered()),this,SLOT(fClose())); file=menuBar()->addMenu(tr("&File"));
file->addAction(newAction);
file->addAction(closeAction);
} void MainWindow::fNew(){
edit->clear();
} void MainWindow::fClose(){
this->close();
} void MainWindow::SetupEditor(){ newBtn=new QPushButton(tr("new"),this);
newBtn->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
connect(newBtn,SIGNAL(clicked()),this,SLOT(fNew())); exit=new QPushButton(tr("exit"),this);
exit->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
connect(exit,SIGNAL(clicked()),this,SLOT(fClose())); edit=new QTextBrowser;
edit->setAcceptRichText(true);
edit->setAutoFormatting(QTextBrowser::AutoNone);
edit->setCursorWidth(1);
edit->setDocumentTitle(tr("new Document"));
edit->setCursorWidth(16);
edit->setReadOnly(false);
edit->setEnabled(true); btnBox=new QHBoxLayout;
btnBox->addWidget(newBtn);
btnBox->addWidget(exit);
}

Main.cpp

#include<QApplication>
#include"MainWindow.h" int main(int argc,char* argv[]){
QApplication app(argc,argv);
MainWindow wnd;
wnd.show();
app.exec(); }

最新文章

  1. 关于iPhone设备不同显示尺寸适配的一些方法
  2. Html.RenderPartial与Html.RenderAction
  3. css省略号布局实例截图
  4. JavaScript DOM 编程艺术(第2版)读书笔记(2)
  5. HDU 4597 Play Game 记忆化DP
  6. android 深入研究ratingbar自定义
  7. Jquery ajax 绑定multiselect多选下拉选项,同时异步执行返回值
  8. hql注意事项一
  9. C语言---字符
  10. Sigar.jar获取系统信息
  11. radio 和checkbox与文字对齐问题
  12. 神奇的魔法数字0x61c88647
  13. ASP.NET 5应用是如何运行的(3)
  14. Hyperledger Fabric 1.0 从零开始(七)——启动Fabric多节点集群
  15. AngularJS学习篇(二十一)
  16. ubuntu 新手入门第一天
  17. webpack 单独打包指定JS文件(CopyWebpackPlugin)
  18. 【shiro】(1)---了解权限管理
  19. Clustering[Evaluation]
  20. DirectUI消息循环的简单封装

热门文章

  1. MySQL之 ALTER vs CHANGE vs MODIFY COLUMN
  2. 搭建环境Visual Studio 2013 社区版
  3. 基于Asterisk的VoIP开发指南——(1)实现基本呼叫功能
  4. bundle install 出现 &amp;#39;gem install mysql2 -v &amp;#39;0.3.15&amp;#39; succeeds before bunding &amp;#39;
  5. 【DateTime格式大全 】
  6. 使用rem设计移动端自适应页面一(转载)
  7. GoogleGoogle搜索解析
  8. 深入理解javascript new的机制
  9. ASP.Net中应用百度编辑器(UEditor)上传图片和上传附件失败-解决方案
  10. iOS基础 - iOS网络基础