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(); }

QT QTextBrowser的更多相关文章

  1. qt 标签 QTextBrowser QLabel

    使用标签控件时我首先想到的就是QLabel,QLabel支持自动换行,并可以解析富文本,是一个不错的选择,这也使的我并没有去深入了解其他的可以有 同样效果的控件,本篇文字我也主要是讲解标签的用法,可以 ...

  2. PyQt(Python+Qt)学习随笔:print标准输出sys.stdout以及stderr重定向QTextBrowser等图形界面对象

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 <在Python实现print标准输出sys.stdout.st ...

  3. Qt QLabel QTextBrowser 实现网址链接

    勾选属性: 并且编辑网址链接: QLabel--点击text属性的...:  QTextBrowser--双击控件

  4. QT 文本html显示格式的问题,如在QTextBrowser.setText用tr(),其中为html格式

    QObject::tr("<h1><font color = green>%1</font>的人品指数:<font color = orange&g ...

  5. qt 工具下的dump工具导出文档出现异常解决方案

    今天一直认为qt环境下的dumpcpp 和dumpdoc两个导出工具很好用,可以今天在导出MSChart组件的类方法文档时,虽然导出成功了,但是导出的结果却是令人失望.自己也不知道如何能够正确导出,就 ...

  6. QT TCP文件上传服务器

    利用QT做为client端,纯C语言做为server端,利用tcp协议,实现client端向server端传递文件 Linux服务器端 //头文件 #include <stdio.h> # ...

  7. QT UDP聊天小程序

    利用QT的UDP技术,实现两个QT程序之间的聊天程序. #ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include < ...

  8. QT 网络编程三(TCP版)

    QT客户端 //widget.h #ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include <QTcpSocket& ...

  9. Qt StyleSheet样式表实例(转)

    QT论坛看到的,收藏一下! 在涉及到Qt 美工的时候首先需要掌握CSS 级联样式表. 下面将通过几个例子来介绍一下怎样使用Qt中的部件类型设计.自定义的前台背景与后台背景的颜色: 如果需要一个文本编辑 ...

随机推荐

  1. Robotium源码分析之Instrumentation进阶-attach

    在分析Robotium的运行原理之前,我们有必要先搞清楚Instrumentation的一些相关知识点,因为Robotium就是基于Instrumentation而开发出来的一套自动化测试框架.鉴于之 ...

  2. Spring AspectJ的Execution表达式-备忘笔记

    Aspectj切入点语法定义 在使用spring框架配置AOP的时候,不管是通过XML配置文件还是注解的方式都需要定义pointcut"切入点" 例如定义切入点表达式  execu ...

  3. Java 异常归纳总结

    1.异常的分类 1) Checked exception: 这类异常都是Exception的子类 .异常的向上抛出机制进行处理,如果子类可能产生A异常,那么在父类中也必须throws A异常.可能导致 ...

  4. C# 标签(条码)

    C# 标签(条码) 上一篇说到条码的打印,主要是通过读取模板定义文件(XML文件),然后结合从数据库中读取的动态数据结合而产生条码.下面主要说一下如何设计这个条码模板.设计过程也很简单,只需要简单的拖 ...

  5. [译]Java 设计模式之迭代器

    (文章翻译自java-design-pattern-iterator) 迭代器模式用于迭代遍历一个集合对象.它是一个经常被用到的模式,你可能以前使用过它.不管在任何时候你看见一些方法像hasNext( ...

  6. dpkg: error processing mysql-server (--configure): dependency problems - leaving unconfigured

    dpkg: error processing mysql-server (--configure): dependency problems - leaving unconfigured start: ...

  7. 学习Sass之安装Sass

    学习Sass之安装Sass 为什么使用Sass 作为前端(html.javascript.css)的三大马车之一的css,一直以静态语言存在,HTML5火遍大江南北了.javascript由于NODE ...

  8. 关于WCF的一些知识点

    首先,WCF和WebService一些区别1,WCF支持多中通信协议,http/https tcp/udp/msmq.命名管道,对等网,消息可达性,事物流等.2,WCF可以与ASP.NET集成,共享同 ...

  9. 【转载】matlab如何判断一个点是否在多面体内

    转载自:http://www.52souji.net/point-within-a-polyhedron/ 我遇到的一个实际问题是:要在空位区域随机放置一定数量的原子,这些原子在空位区域任何一处存在的 ...

  10. Binder机制,从Java到C (1. IPC in Application Remote Service)

    转载请标注:张小燕:http://www.cnblogs.com/zhangxinyan 1. Application 中的 service 我们知道Android中Service有三种类型:Loca ...