QT QTextBrowser
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的更多相关文章
- qt 标签 QTextBrowser QLabel
		
使用标签控件时我首先想到的就是QLabel,QLabel支持自动换行,并可以解析富文本,是一个不错的选择,这也使的我并没有去深入了解其他的可以有 同样效果的控件,本篇文字我也主要是讲解标签的用法,可以 ...
 - PyQt(Python+Qt)学习随笔:print标准输出sys.stdout以及stderr重定向QTextBrowser等图形界面对象
		
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 <在Python实现print标准输出sys.stdout.st ...
 - Qt  QLabel  QTextBrowser 实现网址链接
		
勾选属性: 并且编辑网址链接: QLabel--点击text属性的...: QTextBrowser--双击控件
 - QT 文本html显示格式的问题,如在QTextBrowser.setText用tr(),其中为html格式
		
QObject::tr("<h1><font color = green>%1</font>的人品指数:<font color = orange&g ...
 - qt  工具下的dump工具导出文档出现异常解决方案
		
今天一直认为qt环境下的dumpcpp 和dumpdoc两个导出工具很好用,可以今天在导出MSChart组件的类方法文档时,虽然导出成功了,但是导出的结果却是令人失望.自己也不知道如何能够正确导出,就 ...
 - QT TCP文件上传服务器
		
利用QT做为client端,纯C语言做为server端,利用tcp协议,实现client端向server端传递文件 Linux服务器端 //头文件 #include <stdio.h> # ...
 - QT UDP聊天小程序
		
利用QT的UDP技术,实现两个QT程序之间的聊天程序. #ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include < ...
 - QT 网络编程三(TCP版)
		
QT客户端 //widget.h #ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include <QTcpSocket& ...
 - Qt StyleSheet样式表实例(转)
		
QT论坛看到的,收藏一下! 在涉及到Qt 美工的时候首先需要掌握CSS 级联样式表. 下面将通过几个例子来介绍一下怎样使用Qt中的部件类型设计.自定义的前台背景与后台背景的颜色: 如果需要一个文本编辑 ...
 
随机推荐
- Visual Studio 单元测试之二---顺序单元测试
			
原文:Visual Studio 单元测试之二---顺序单元测试 此文是上一篇博文:Visual Studio 单元测试之一---普通单元测试的后续篇章.如果读者对Visual Studio的单元测试 ...
 - [翻译]如何编写GIMP插件(二)
			
写在前面: 本人翻译并不专业,甚至英语不好,翻译内容仅供参考.由于博主是边学边翻译,所以不能保证翻译的准确性和正确性,如果可以,请查看原版学习,本文仅作学习记录之用. <How to write ...
 - C#实现文档转换成PDF
			
网上有很多将doc.ppt.xls等类型的文档转换成pdf的方法,目前了解到的有两大类: 1.使用虚拟打印机将doc.ppt.xls等类型的文档 2.使用OFFICE COM组件 我采用了第二种方法实 ...
 - 多线程中lock用法的经典实例
			
多线程中lock用法的经典实例 一.Lock定义 lock 关键字可以用来确保代码块完成运行,而不会被其他线程中断.它可以把一段代码定义为互斥段(critical section),互斥段在一 ...
 - 使用Eclipse开始Java编程
			
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/start-java-programing ...
 - iOS基础 - Quartz 2D绘图的基本步骤
			
一.使用Quartz 2D绘图的基本步骤 1) 获取上下文context(绘制图形的地方) 2) 设置路径(路径是用来描述形状的) 3) 将路径添加到上下文 4) 设置上下文属性(设置颜色,线宽, ...
 - Restful?
			
为什么要Restful?为什么不Restful? 本随笔不说为什么要Restful,只说为什么不Restful.首先Http是超文本转移协议而不是控制协议.通常文档中也会使用“资源”来指代超文本. ...
 - tornado\ioloop.py单例
			
@staticmethod def instance(): """Returns a global `IOLoop` instance. Most application ...
 - PRML 第三章 - 线性回归
			
这段时间组里在有计划地学习书籍PRML (Pattern Recognition and Machine Learning),前两天自己做了一个里面第三章linear regression的分享,这里 ...
 - Myeclipse 10 for mac 破解版下载安装及破解方法
			
下载地址:http://pan.baidu.com/share/link?shareid=463687&uk=1798617416 解压下载好的压缩包Myeclipse 10 for mac+ ...