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. a链接bug

    <a href=”javascript:void(0);” class="btn" id="btn"></a> 在ios系统中(andr ...

  2. ZooKeeper 主要的操作演示样品

    // 创建一个与server的连接 ZooKeeper zk = new ZooKeeper("localhost:" + CLIENT_PORT, ClientBase.CONN ...

  3. thinkphp 支付宝错误 Class 'Think' not found

    Class 'Think' not found D:\www\DonatePlatform\ThinkPHP\Extend\Vendor\alipay\lib\alipay_submit.class. ...

  4. leetcode第九题--Palindrome Number

    Problem: Determine whether an integer is a palindrome. Do this without extra space. click to show sp ...

  5. vs2012运行项目提示无法连接 asp.net development server的解决方案

    更改本项目的.sln文件的端口号即可:如果还不行的话,多试几次:

  6. Qt的SQL操作,DELETE,SELECT

    #include <QObject> #include <QSqlDatabase> #include <QSqlError> #include <QSqlQ ...

  7. 使用Eclipse开始Java编程

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/start-java-programing ...

  8. iOS基础 - 通知中心(NSNotificationCenter)

    通知中心(NSNotificationCenter) 每一个应用程序都有一个通知中心(NSNotificationCenter)实例,专门负责协助不同对象之间的消息通信 任何一个对象都可以向通知中心发 ...

  9. 附加被分离DB

    如何附加被分离的质疑数据库?   简介 有些时间,由于日志损坏等原因,导致了数据库质疑.如果此时你分离了数据库,那你会发现你无法再附加上数据库,那后果还是很严重的.因此本文提供了一种方式,可以使得当数 ...

  10. ubuntu下无法打开windows下ntfs文件系统的解决方法

    例如:/dev/sda5无法加载,使用如下命令 sudo ntfsfix /dev/sda5 如果命令没有安装,先安装(sudo apt-get install ntfsprogs).