QT QTextBrowser
2024-09-26 18:46:52
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(); }
最新文章
- 关于iPhone设备不同显示尺寸适配的一些方法
- Html.RenderPartial与Html.RenderAction
- css省略号布局实例截图
- JavaScript DOM 编程艺术(第2版)读书笔记(2)
- HDU 4597 Play Game 记忆化DP
- android 深入研究ratingbar自定义
- Jquery ajax 绑定multiselect多选下拉选项,同时异步执行返回值
- hql注意事项一
- C语言---字符
- Sigar.jar获取系统信息
- radio 和checkbox与文字对齐问题
- 神奇的魔法数字0x61c88647
- ASP.NET 5应用是如何运行的(3)
- Hyperledger Fabric 1.0 从零开始(七)——启动Fabric多节点集群
- AngularJS学习篇(二十一)
- ubuntu 新手入门第一天
- webpack 单独打包指定JS文件(CopyWebpackPlugin)
- 【shiro】(1)---了解权限管理
- Clustering[Evaluation]
- DirectUI消息循环的简单封装
热门文章
- MySQL之 ALTER vs CHANGE vs MODIFY COLUMN
- 搭建环境Visual Studio 2013 社区版
- 基于Asterisk的VoIP开发指南——(1)实现基本呼叫功能
- bundle install 出现 &;#39;gem install mysql2 -v &;#39;0.3.15&;#39; succeeds before bunding &;#39;
- 【DateTime格式大全 
】
- 使用rem设计移动端自适应页面一(转载)
- GoogleGoogle搜索解析
- 深入理解javascript new的机制
- ASP.Net中应用百度编辑器(UEditor)上传图片和上传附件失败-解决方案
- iOS基础 - iOS网络基础