29.QT主窗口加widget
运行效果
- widget布局showwidget.h
#ifndef SHOWWIDGET_H
#define SHOWWIDGET_H #include <QWidget>
#include <QLabel>
#include <QTextEdit>
#include <QImage> class ShowWidget : public QWidget
{
Q_OBJECT
public:
explicit ShowWidget(QWidget *parent = );
//图片
QImage img;
//标签
QLabel *imageLabel;
//编辑框
QTextEdit *text;
signals: public slots: }; #endif // SHOWWIDGET_H - showwidget.cpp
#include "showwidget.h"
#include <QHBoxLayout>
ShowWidget::ShowWidget(QWidget *parent) :
QWidget(parent)
{
imageLabel =new QLabel;
imageLabel->setScaledContents(true); text =new QTextEdit; //创建水平布局
QHBoxLayout *mainLayout =new QHBoxLayout(this);
mainLayout->addWidget(imageLabel);
mainLayout->addWidget(text);
} - 主窗口创建(工具栏,菜单项) imgprocessor.h
#ifndef IMGPROCESSOR_H
#define IMGPROCESSOR_H #include <QMainWindow>
#include <QImage>
#include <QLabel>
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QComboBox>
#include <QSpinBox>
#include <QToolBar>
#include <QFontComboBox>
#include <QToolButton>
#include <QTextCharFormat>
#include "showwidget.h" class ImgProcessor : public QMainWindow
{
Q_OBJECT public:
ImgProcessor(QWidget *parent = );
~ImgProcessor(); void createActions(); //创建动作
void createMenus(); //创建菜单
void createToolBars(); //创建工具栏 void loadFile(QString filename);
void mergeFormat(QTextCharFormat); private:
//创建工具栏动作
QMenu *fileMenu; //文件菜单栏
QMenu *zoomMenu; //编辑菜单栏
QMenu *rotateMenu; //选择菜单栏
QMenu *mirrorMenu; //镜像菜单栏 QImage img; //图片资源
QString fileName; //文件名
ShowWidget *showWidget; //显示窗口 QAction *openFileAction; //打开文件
QAction *NewFileAction; //新建文件
QAction *PrintTextAction; //打印文本
QAction *PrintImageAction; //打印图片
QAction *exitAction; //退出 QAction *copyAction; //复制
QAction *cutAction; //剪切
QAction *pasteAction; //粘贴
QAction *aboutAction; //关于
QAction *zoomInAction; //放大
QAction *zoomOutAction; //缩小 QAction *rotate90Action; //旋转90度
QAction *rotate180Action; //旋转180度
QAction *rotate270Action; //旋转270度 QAction *mirrorVerticalAction; //纵向镜像
QAction *mirrorHorizontalAction; //横向镜像 QAction *undoAction;
QAction *redoAction; QToolBar *fileTool; //文件工具栏
QToolBar *zoomTool; //复制粘贴工具栏
QToolBar *rotateTool; //放大缩小工具栏
QToolBar *mirrorTool; //旋转工具栏 QToolBar *doToolBar; //撤回工具栏 QLabel *fontLabel1; //字体设置项
QFontComboBox *fontComboBox;
QLabel *fontLabel2; //字号设置项
QComboBox *sizeComboBox;
QToolButton *boldBtn; //加粗
QToolButton *italicBtn; //倾斜
QToolButton *underlineBtn; //下划线
QToolButton *colorBtn; //颜色 QToolBar *fontToolBar; //字体工具栏 QLabel *listLabel; //排序设置项
QComboBox *listComboBox;
QActionGroup *actGrp; //对齐方式设置
QAction *leftAction; //左对齐
QAction *rightAction; //右对齐
QAction *centerAction; //中间对齐
QAction *justifyAction; //两端对齐 QToolBar *listToolBar; //排序工具栏 protected slots:
//显示文件
void ShowNewFile();
//打开文件
void ShowOpenFile();
//显示文本
void ShowPrintText();
//显示图片
void ShowPrintImage();
void ShowZoomIn();
void ShowZoomOut();
//旋转九十度
void ShowRotate90();
//旋转180度
void ShowRotate180();
//旋转270度
void ShowRotate270();
//纵向镜像
void ShowMirrorVertical();
//横向镜像
void ShowMirrorHorizontal();
//设置字体框
void ShowFontComboBox(QString comboStr);
//设置大小框
void ShowSizeSpinBox(QString spinValue);
//设置字体加粗
void ShowBoldBtn();
//设置倾斜
void ShowItalicBtn();
//设置下划线
void ShowUnderlineBtn();
//设置颜色框
void ShowColorBtn();
void ShowCurrentFormatChanged(const QTextCharFormat &fmt); void ShowList(int);
void ShowAlignment(QAction *act);
void ShowCursorPositionChanged();
}; #endif // IMGPROCESSOR_H - imgprocessor.cpp
#include "imgprocessor.h"
#include <QFileDialog>
#include <QFile>
#include <QTextStream>
#include <QtPrintSupport/QPrintDialog>
#include <QtPrintSupport/QPrinter>
#include <QColorDialog>
#include <QColor>
#include <QTextList>
#include <qpainter.h> //构造初始化
ImgProcessor::ImgProcessor(QWidget *parent)
: QMainWindow(parent)
{
//设置标题
setWindowTitle(tr("Easy Word")); //创建显示
showWidget =new ShowWidget(this);
//设置中心控件为showWidget
setCentralWidget(showWidget); //在工具栏上嵌入控件
//设置字体
fontLabel1 =new QLabel(tr("字体:"));
fontComboBox =new QFontComboBox;
fontComboBox->setFontFilters(QFontComboBox::ScalableFonts); //设置字号
fontLabel2 =new QLabel(tr("字号:"));
sizeComboBox =new QComboBox;
QFontDatabase db;
foreach(int size,db.standardSizes())
sizeComboBox->addItem(QString::number(size)); //设置加粗按钮
boldBtn =new QToolButton;
//设置图片
boldBtn->setIcon(QIcon("bold.png"));
//设置可以选中
boldBtn->setCheckable(true); //设置倾斜
italicBtn =new QToolButton;
italicBtn->setIcon(QIcon("italic.png"));
italicBtn->setCheckable(true); //设置下划线
underlineBtn =new QToolButton;
underlineBtn->setIcon(QIcon("underline.png"));
underlineBtn->setCheckable(true); //设置颜色
colorBtn =new QToolButton;
colorBtn->setIcon(QIcon("color.png"));
colorBtn->setCheckable(true); //排序方式
listLabel =new QLabel(tr("排序"));
listComboBox =new QComboBox;
listComboBox->addItem("Standard");
listComboBox->addItem("QTextListFormat::ListDisc");
listComboBox->addItem("QTextListFormat::ListCircle");
listComboBox->addItem("QTextListFormat::ListSquare");
listComboBox->addItem("QTextListFormat::ListDecimal");
listComboBox->addItem("QTextListFormat::ListLowerAlpha");
listComboBox->addItem("QTextListFormat::ListUpperAlpha");
listComboBox->addItem("QTextListFormat::ListLowerRoman");
listComboBox->addItem("QTextListFormat::ListUpperRoman"); //创建Action
createActions();
//创建菜单栏
createMenus();
//创建工具栏
createToolBars(); //载入图片
if(img.load("image.png"))
{
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
} //字体框连接到函数
connect(fontComboBox,SIGNAL(activated(QString)),this,SLOT(ShowFontComboBox(QString)));
//字体大小框连接到函数
connect(sizeComboBox,SIGNAL(activated(QString)),this,SLOT(ShowSizeSpinBox(QString)));
//加粗连接到函数
connect(boldBtn,SIGNAL(clicked()),this,SLOT(ShowBoldBtn()));
//斜体连接到函数
connect(italicBtn,SIGNAL(clicked()),this,SLOT(ShowItalicBtn()));
//下划线连接到函数
connect(underlineBtn,SIGNAL(clicked()),this,SLOT(ShowUnderlineBtn()));
//颜色按钮连接到函数
connect(colorBtn,SIGNAL(clicked()),this,SLOT(ShowColorBtn()));
//文本字体变化连接到函数
connect(showWidget->text,SIGNAL(currentCharFormatChanged(QtextCharFormat&)),this,SLOT(ShowCurrentFormatChanged(QTextCharFormat&))); //排序方式连接到函数
connect(listComboBox,SIGNAL(activated(int)),this,SLOT(ShowList(int))); connect(showWidget->text->document(),SIGNAL(undoAvailable(bool)),redoAction,SLOT(setEnabled(bool)));
connect(showWidget->text->document(),SIGNAL(redoAvailable(bool)),redoAction,SLOT(setEnabled(bool)));
//文本位置的鼠标变化连接到函数
connect(showWidget->text,SIGNAL(cursorPositionChanged()),this,SLOT(ShowCursorPositionChanged()));
} ImgProcessor::~ImgProcessor()
{ } //创建工具栏的动作
void ImgProcessor::createActions()
{
//"打开"动作
openFileAction =new QAction(QIcon("open.png"),tr("打开"),this);
//设置快捷键
openFileAction->setShortcut(tr("Ctrl+O"));
//设置提示
openFileAction->setStatusTip(tr("打开一个文件"));
//打开选项连接到函数
connect(openFileAction,SIGNAL(triggered()),this,SLOT(ShowOpenFile())); //"新建"动作
NewFileAction =new QAction(QIcon("new.png"),tr("新建"),this);
NewFileAction->setShortcut(tr("Ctrl+N"));
NewFileAction->setStatusTip(tr("新建一个文件"));
connect(NewFileAction,SIGNAL(triggered()),this,SLOT(ShowNewFile())); //"退出"动作
exitAction =new QAction(tr("退出"),this);
exitAction->setShortcut(tr("Ctrl+Q"));
exitAction->setStatusTip(tr("退出程序"));
connect(exitAction,SIGNAL(triggered()),this,SLOT(close())); //"复制"动作
copyAction =new QAction(QIcon("copy.png"),tr("复制"),this);
copyAction->setShortcut(tr("Ctrl+C"));
copyAction->setStatusTip(tr("复制文件"));
connect(copyAction,SIGNAL(triggered()),showWidget->text,SLOT(copy())); //"剪切"动作
cutAction =new QAction(QIcon("cut.png"),tr("剪切"),this);
cutAction->setShortcut(tr("Ctrl+X"));
cutAction->setStatusTip(tr("剪切文件"));
connect(cutAction,SIGNAL(triggered()),showWidget->text,SLOT(cut())); //"粘贴"动作
pasteAction =new QAction(QIcon("paste.png"),tr("粘贴"),this);
pasteAction->setShortcut(tr("Ctrl+V"));
pasteAction->setStatusTip(tr("粘贴文件"));
connect(pasteAction,SIGNAL(triggered()),showWidget->text,SLOT(paste())); //"关于"动作
aboutAction =new QAction(tr("关于"),this);
connect(aboutAction,SIGNAL(triggered()),this,SLOT(QApplication::aboutQt())); //"打印文本"动作
PrintTextAction =new QAction(QIcon("printText.png"),tr("打印文本"), this);
PrintTextAction->setStatusTip(tr("打印一个文本"));
connect(PrintTextAction,SIGNAL(triggered()),this,SLOT(ShowPrintText())); //"打印图像"动作
PrintImageAction =new QAction(QIcon("printImage.png"),tr("打印图像"), this);
PrintImageAction->setStatusTip(tr("打印一幅图像"));
connect(PrintImageAction,SIGNAL(triggered()),this,SLOT(ShowPrintImage())); //"放大"动作
zoomInAction =new QAction(QIcon("zoomin.png"),tr("放大"),this);
zoomInAction->setStatusTip(tr("放大一张图片"));
connect(zoomInAction,SIGNAL(triggered()),this,SLOT(ShowZoomIn())); //"缩小"动作
zoomOutAction =new QAction(QIcon("zoomout.png"),tr("缩小"),this);
zoomOutAction->setStatusTip(tr("缩小一张图片"));
connect(zoomOutAction,SIGNAL(triggered()),this,SLOT(ShowZoomOut())); //实现图像旋转的动作(Action)
//旋转90°
rotate90Action =new QAction(QIcon("rotate90.png"),tr("旋转90°"),this);
rotate90Action->setStatusTip(tr("将一幅图旋转90°"));
connect(rotate90Action,SIGNAL(triggered()),this,SLOT(ShowRotate90())); //旋转180°
rotate180Action =new QAction(QIcon("rotate180.png"),tr("旋转180°"), this);
rotate180Action->setStatusTip(tr("将一幅图旋转180°"));
connect(rotate180Action,SIGNAL(triggered()),this,SLOT(ShowRotate180())); //旋转270°
rotate270Action =new QAction(QIcon("rotate270.png"),tr("旋转270°"), this);
rotate270Action->setStatusTip(tr("将一幅图旋转270°"));
connect(rotate270Action,SIGNAL(triggered()),this,SLOT(ShowRotate270())); //实现图像镜像的动作(Action)
//纵向镜像
mirrorVerticalAction =new QAction(tr ("纵向镜像"),this);
mirrorVerticalAction->setStatusTip(tr("对一张图作纵向镜像"));
connect(mirrorVerticalAction,SIGNAL(triggered()),this,SLOT(ShowMirrorVertical())); //横向镜像
mirrorHorizontalAction =new QAction(tr("横向镜像"),this);
mirrorHorizontalAction->setStatusTip(tr("对一张图作横向镜像"));
connect(mirrorHorizontalAction,SIGNAL(triggered()),this,SLOT(ShowMirrorHorizontal())); //排序:左对齐、右对齐、居中和两端对齐
actGrp =new QActionGroup(this); leftAction =new QAction(QIcon("left.png"),"左对齐",actGrp);
leftAction->setCheckable(true); rightAction =new QAction(QIcon("right.png"),"右对齐",actGrp);
rightAction->setCheckable(true); centerAction =new QAction(QIcon("center.png"),"居中",actGrp);
centerAction->setCheckable(true); justifyAction =new QAction(QIcon("justify.png"),"两端对齐",actGrp);
justifyAction->setCheckable(true); connect(actGrp,SIGNAL(triggered(QAction*)),this,SLOT(ShowAlignment(QAction*))); //实现撤销和重做的动作(Action)
//撤销和重做
undoAction =new QAction(QIcon("undo.png"),"撤销",this);
connect(undoAction,SIGNAL(triggered()),showWidget->text,SLOT(undo()));
redoAction =new QAction(QIcon("redo.png"),"重做",this);
connect(redoAction,SIGNAL(triggered()),showWidget->text,SLOT(redo()));
} void ImgProcessor::createMenus()
{
//文件菜单
fileMenu =menuBar()->addMenu(tr("文件"));
fileMenu->addAction(openFileAction);
fileMenu->addAction(NewFileAction);
fileMenu->addAction(PrintTextAction);
fileMenu->addAction(PrintImageAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction); //缩放菜单
zoomMenu =menuBar()->addMenu(tr("编辑"));
zoomMenu->addAction(copyAction);
zoomMenu->addAction(cutAction);
zoomMenu->addAction(pasteAction);
zoomMenu->addAction(aboutAction);
zoomMenu->addSeparator();
zoomMenu->addAction(zoomInAction);
zoomMenu->addAction(zoomOutAction); //旋转菜单
rotateMenu =menuBar()->addMenu(tr("旋转"));
rotateMenu->addAction(rotate90Action);
rotateMenu->addAction(rotate180Action);
rotateMenu->addAction(rotate270Action); //镜像菜单
mirrorMenu =menuBar()->addMenu(tr("镜像"));
mirrorMenu->addAction(mirrorVerticalAction);
mirrorMenu->addAction(mirrorHorizontalAction);
} //创建工具栏
void ImgProcessor::createToolBars()
{
//文件工具条
fileTool =addToolBar("File");
fileTool->addAction(openFileAction);
fileTool->addAction(NewFileAction);
fileTool->addAction(PrintTextAction);
fileTool->addAction(PrintImageAction); //编辑工具条
zoomTool =addToolBar("Edit");
zoomTool->addAction(copyAction);
zoomTool->addAction(cutAction);
zoomTool->addAction(pasteAction);
zoomTool->addSeparator();
zoomTool->addAction(zoomInAction);
zoomTool->addAction(zoomOutAction); //旋转工具条
rotateTool =addToolBar("rotate");
rotateTool->addAction(rotate90Action);
rotateTool->addAction(rotate180Action);
rotateTool->addAction(rotate270Action); //撤销和重做工具条
doToolBar =addToolBar("doEdit");
doToolBar->addAction(undoAction);
doToolBar->addAction(redoAction); //字体工具条
fontToolBar =addToolBar("Font");
fontToolBar->addWidget(fontLabel1);
fontToolBar->addWidget(fontComboBox);
fontToolBar->addWidget(fontLabel2);
fontToolBar->addWidget(sizeComboBox);
fontToolBar->addSeparator();
fontToolBar->addWidget(boldBtn);
fontToolBar->addWidget(italicBtn);
fontToolBar->addWidget(underlineBtn);
fontToolBar->addSeparator();
fontToolBar->addWidget(colorBtn); //排序工具条
listToolBar =addToolBar("list");
listToolBar->addWidget(listLabel);
listToolBar->addWidget(listComboBox);
listToolBar->addSeparator();
listToolBar->addActions(actGrp->actions());
} //新建一个文件
void ImgProcessor::ShowNewFile()
{
ImgProcessor *newImgProcessor =new ImgProcessor;
newImgProcessor->show();
} //打开一个文件
void ImgProcessor::ShowOpenFile()
{
fileName =QFileDialog::getOpenFileName(this,"打开","*.*");
if(!fileName.isEmpty())
{
if(showWidget->text->document()->isEmpty())
{
loadFile(fileName);
}
else
{
ImgProcessor *newImgProcessor =new ImgProcessor;
newImgProcessor->show();
newImgProcessor->loadFile(fileName);
}
}
} //载入一个文件
void ImgProcessor::loadFile(QString filename)
{
printf("file name:%s\n",filename.data()); QFile file(filename);
if(file.open(QIODevice::ReadOnly|QIODevice::Text))
{
QTextStream textStream(&file);
while(!textStream.atEnd())
{
showWidget->text->append(textStream.readLine());
printf("read line\n");
}
printf("end\n");
}
} //显示打印文字效果
void ImgProcessor::ShowPrintText()
{
QPrinter printer;
QPrintDialog printDialog(&printer,this);
if(printDialog.exec())
{
QTextDocument *doc =showWidget->text->document();
doc->print(&printer);
}
} //显示打印图片效果
void ImgProcessor::ShowPrintImage()
{
QPrinter printer;
QPrintDialog printDialog(&printer,this);
if(printDialog.exec())
{
QPainter painter(&printer);
QRect rect =painter.viewport();
QSize size = img.size();
size.scale(rect.size(),Qt::KeepAspectRatio); painter.setViewport(rect.x(),rect.y(),size.width(),size.height());
painter.setWindow(img.rect());
painter.drawImage(,,img);
}
} //放大一张图片
void ImgProcessor::ShowZoomIn()
{
if(img.isNull())
return;
QMatrix martix;
martix.scale(,);
img = img.transformed(martix);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
} //缩小一张图片
void ImgProcessor::ShowZoomOut()
{
if(img.isNull())
return;
QMatrix matrix;
matrix.scale(0.5,0.5);
img = img.transformed(matrix);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
} //旋转90度
void ImgProcessor::ShowRotate90()
{
if(img.isNull())
return;
QMatrix matrix;
matrix.rotate();
img = img.transformed(matrix);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
} //旋转180度
void ImgProcessor::ShowRotate180()
{
if(img.isNull())
return;
QMatrix matrix;
matrix.rotate();
img = img.transformed(matrix);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
} //旋转270度
void ImgProcessor::ShowRotate270()
{
if(img.isNull())
return;
QMatrix matrix;
matrix.rotate();
img = img.transformed(matrix);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
} //水平镜像
void ImgProcessor::ShowMirrorVertical()
{
if(img.isNull())
return;
img=img.mirrored(false,true);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
} //垂直镜像
void ImgProcessor::ShowMirrorHorizontal()
{
if(img.isNull())
return;
img=img.mirrored(true,false);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
} //设置字体
void ImgProcessor::ShowFontComboBox(QString comboStr)
{
QTextCharFormat fmt;
fmt.setFontFamily(comboStr);
mergeFormat(fmt); //把新的格式应用到光标选区内的字符
} //把新的格式应用到光标选区内的字符
void ImgProcessor::mergeFormat(QTextCharFormat format)
{
QTextCursor cursor =showWidget->text->textCursor();
if(!cursor.hasSelection())
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format);
showWidget->text->mergeCurrentCharFormat(format);
} //设置字号
void ImgProcessor::ShowSizeSpinBox(QString spinValue)
{
QTextCharFormat fmt;
fmt.setFontPointSize(spinValue.toFloat());
showWidget->text->mergeCurrentCharFormat(fmt);
} //设置文字显示加粗
void ImgProcessor::ShowBoldBtn()
{
QTextCharFormat fmt;
fmt.setFontWeight(boldBtn->isChecked()?QFont::Bold:QFont::Normal);
showWidget->text->mergeCurrentCharFormat(fmt);
} //设置文字显示斜体
void ImgProcessor::ShowItalicBtn()
{
QTextCharFormat fmt;
fmt.setFontItalic(italicBtn->isChecked());
showWidget->text->mergeCurrentCharFormat(fmt);
} //设置文字加下画线
void ImgProcessor::ShowUnderlineBtn()
{
QTextCharFormat fmt;
fmt.setFontUnderline(underlineBtn->isChecked());
showWidget->text->mergeCurrentCharFormat(fmt);
} //设置文字颜色
void ImgProcessor::ShowColorBtn()
{
QColor color=QColorDialog::getColor(Qt::red,this);
if(color.isValid())
{
QTextCharFormat fmt;
fmt.setForeground(color);
showWidget->text->mergeCurrentCharFormat(fmt);
}
} //设置文字改变
void ImgProcessor::ShowCurrentFormatChanged(const QTextCharFormat &fmt)
{
fontComboBox->setCurrentIndex(fontComboBox->findText(fmt.fontFamily()));
sizeComboBox->setCurrentIndex(sizeComboBox->findText(QString::number(fmt.fontPointSize())));
boldBtn->setChecked(fmt.font().bold());
italicBtn->setChecked(fmt.fontItalic());
underlineBtn->setChecked(fmt.fontUnderline());
} //设置对齐
void ImgProcessor::ShowAlignment(QAction *act)
{
if(act==leftAction)
showWidget->text->setAlignment(Qt::AlignLeft);
if(act==rightAction)
showWidget->text->setAlignment(Qt::AlignRight);
if(act==centerAction)
showWidget->text->setAlignment(Qt::AlignCenter);
if(act==justifyAction)
showWidget->text->setAlignment(Qt::AlignJustify);
} //鼠标位置改变
void ImgProcessor::ShowCursorPositionChanged()
{
if(showWidget->text->alignment()==Qt::AlignLeft)
leftAction->setChecked(true);
if(showWidget->text->alignment()==Qt::AlignRight)
rightAction->setChecked(true);
if(showWidget->text->alignment()==Qt::AlignCenter)
centerAction->setChecked(true);
if(showWidget->text->alignment()==Qt::AlignJustify)
justifyAction->setChecked(true);
} //设置排序方式
void ImgProcessor::ShowList(int index)
{
QTextCursor cursor=showWidget->text->textCursor(); if(index!=)
{
QTextListFormat::Style style=QTextListFormat::ListDisc;
switch(index) //设置style属性值
{
default:
case :
style=QTextListFormat::ListDisc; break;
case :
style=QTextListFormat::ListCircle; break;
case :
style=QTextListFormat::ListSquare; break;
case :
style=QTextListFormat::ListDecimal; break;
case :
style=QTextListFormat::ListLowerAlpha; break;
case :
style=QTextListFormat::ListUpperAlpha; break;
case :
style=QTextListFormat::ListLowerRoman; break;
case :
style=QTextListFormat::ListUpperRoman; break;
}
cursor.beginEditBlock(); //设置缩进值 QTextBlockFormat blockFmt=cursor.blockFormat();
QTextListFormat listFmt; if(cursor.currentList())
{
listFmt= cursor.currentList()->format();
}
else
{
listFmt.setIndent(blockFmt.indent()+);
blockFmt.setIndent();
cursor.setBlockFormat(blockFmt);
}
listFmt.setStyle(style);
cursor.createList(listFmt); cursor.endEditBlock();
}
else
{
QTextBlockFormat bfmt;
bfmt.setObjectIndex(-);
cursor.mergeBlockFormat(bfmt);
}
} - main.cpp
#include "showwidget.h"
#include "imgprocessor.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//ShowWidget w;
ImgProcessor w;
w.show(); return a.exec();
}
29.QT主窗口加widget的更多相关文章
- QT 主窗口和子窗口相互切换示例
QT 主窗口和子窗口相互切换示例 文件列表: SubWidget.h #ifndef SUBWIDGET_H #define SUBWIDGET_H #include <QtWidgets/QW ...
- Qt Widgets——主窗口及其主要组成部分
Main Window and Related Classes QAction 动作类,用于当做一个菜单项或工具项插入菜单或工具栏 QActionGroup 动作组,用于管理多个动作,设置它们之间的互 ...
- [Qt Creator 快速入门] 第5章 应用程序主窗口
对于日常见到的应用程序而言,许多都是基于主窗口的,主窗口中包含了菜单栏.工具栏.状态栏和中心区域等.这一章会详细介绍主窗口的每一个部分,还会涉及资源管理.富文本处理.拖放操作和文档打印等相关内容.重点 ...
- PyQt(Python+Qt)学习随笔:Qt Designer中主窗口对象的tabShape属性
tabShape属性用于控制主窗口标签部件(Tab Widget)中的标签的形状,对应类型为QTabWidget.TabShape,有两种取值: 1.QTabWidget.Rounded:对应值为0, ...
- 第15.11节 PyQt(Python+Qt)入门学习:Qt Designer(设计师)组件Property Editor(属性编辑)界面中主窗口QMainWindow类相关属性详解
概述 主窗口对象是在新建窗口对象时,选择main window类型的模板时创建的窗口对象,如图: 在属性编辑界面中,主窗口对象与QMainWindow相关的属性包括:iconSize.toolButt ...
- Qt实现基本QMainWindow主窗口程序
这个实验用Qt实现基本QMainWindow主窗口 先上实验效果图 打开一个文件,读取文件类容 详细步骤: 1.打开Qt creator新建MainWindow工程 右键工程名添加新文件,mai ...
- Qt中的主窗口之菜单栏
1.Qt中的主窗口 主窗口为建立应用程序用户界面提供了一个框架 Qt开发平台中直接支持主窗口的概念 QMainWindow是Qt中主窗口的基类 QMainWindow继承于QWidget是一种容器类型 ...
- Qt学习之对话框与主窗口的创建
Qt中的信号与槽机制 qt中槽和普通的C++成员函数几乎是一样的--可以是虚函数,可以被重载,可以是共有的,保护的或者私有的. 槽可以和信号连接在一起,在这种情况下,每当发射这个信号的信号,就会自动调 ...
- 如何获得 Qt窗口部件在主窗口中的位置--确定鼠标是否在某一控件上与在控件上的位置
用Qt Creator 设计程序时,最方便的就是ui设计器,可以很容易的得到想要的布局. 但是这样自动布局带来的后果是很难知道窗口中某一部件在主窗口中的相对位置. 在处理子窗口鼠标事件时变的很麻烦.主 ...
随机推荐
- Walking on the path of Redis --- Introduction and Installation
废话开篇 以前从来没听说过有Redis这么个玩意,无意间看到一位仁兄的博客,才对其有所了解,所以决定对其深入了解下.有不对的地方还请各位指正. Redis介绍 下面是官方的介绍,不喜欢english的 ...
- ubuntu下安装 nginx + php + memcached + mariadb
一,apt-get 安装 1,安装nginx sudo apt-get install nginx 所有的配置文件都在/etc/nginx下,虚拟主机配置在/etc/nginx/sites-avail ...
- CGContext与上下文
上下文指的是场景拥有的资源或属性. 上下文的操作包含上下文的设置: 和上下文的引用. 上下文是一个结构体. 主要包含结构体的设置和使用.
- type="radio"样式修改
input[type=radio],input[type=checkbox] { display: inline-block; vertical-align: middle; width: 20px; ...
- MongoDB_pymongo
python使用pymongo访问MongoDB的基本操作 安装pymongo: pip install pymongo from pymongo import MongoClient import ...
- [IOI2011]Race $O(nlog^{2}n)$ 做法
这个应该还不是正解,明天看一下正解到底是什么... Code: #include<bits/stdc++.h> #define setIO(s) freopen(s".in&qu ...
- nginx强制使用https访问(多站点多域名配置)
很多配置过https模板的人都知道,配置https 时 ,站在用户的角度http 和https 的区别根本不清楚.有时候敲 http 时会出现 404 错误,而实际上我们是https. 有朋友找我配置 ...
- 取得Linux系统的各种统计信息
本文基于Linux 2.6.x内核 一.取得CPU信息(相关文件/proc/stat) 在一个系统中的/proct/stat文件内容如下 $ cat /proc/stat cpu 1039426 17 ...
- 使用awk提取字符串中的数字或字母
1.提取字符串中的数字 $ echo 'dsFUs34tg*fs5a%8ar%$#@' |awk -F "" ' { for(i=1;i<=NF;i++) { if ($i ...
- Tab 切换效果
今天写的两个小效果都是为了测试我写的单参函数,结果还是有点成功的~~此处是不是想发表情包! Tab效果很简单,这里我就不赘述了,直接上代码: html代码: <div class="c ...