运行效果

  • 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的更多相关文章

  1. QT 主窗口和子窗口相互切换示例

    QT 主窗口和子窗口相互切换示例 文件列表: SubWidget.h #ifndef SUBWIDGET_H #define SUBWIDGET_H #include <QtWidgets/QW ...

  2. Qt Widgets——主窗口及其主要组成部分

    Main Window and Related Classes QAction 动作类,用于当做一个菜单项或工具项插入菜单或工具栏 QActionGroup 动作组,用于管理多个动作,设置它们之间的互 ...

  3. [Qt Creator 快速入门] 第5章 应用程序主窗口

    对于日常见到的应用程序而言,许多都是基于主窗口的,主窗口中包含了菜单栏.工具栏.状态栏和中心区域等.这一章会详细介绍主窗口的每一个部分,还会涉及资源管理.富文本处理.拖放操作和文档打印等相关内容.重点 ...

  4. PyQt(Python+Qt)学习随笔:Qt Designer中主窗口对象的tabShape属性

    tabShape属性用于控制主窗口标签部件(Tab Widget)中的标签的形状,对应类型为QTabWidget.TabShape,有两种取值: 1.QTabWidget.Rounded:对应值为0, ...

  5. 第15.11节 PyQt(Python+Qt)入门学习:Qt Designer(设计师)组件Property Editor(属性编辑)界面中主窗口QMainWindow类相关属性详解

    概述 主窗口对象是在新建窗口对象时,选择main window类型的模板时创建的窗口对象,如图: 在属性编辑界面中,主窗口对象与QMainWindow相关的属性包括:iconSize.toolButt ...

  6. Qt实现基本QMainWindow主窗口程序

    这个实验用Qt实现基本QMainWindow主窗口 先上实验效果图    打开一个文件,读取文件类容 详细步骤: 1.打开Qt creator新建MainWindow工程 右键工程名添加新文件,mai ...

  7. Qt中的主窗口之菜单栏

    1.Qt中的主窗口 主窗口为建立应用程序用户界面提供了一个框架 Qt开发平台中直接支持主窗口的概念 QMainWindow是Qt中主窗口的基类 QMainWindow继承于QWidget是一种容器类型 ...

  8. Qt学习之对话框与主窗口的创建

    Qt中的信号与槽机制 qt中槽和普通的C++成员函数几乎是一样的--可以是虚函数,可以被重载,可以是共有的,保护的或者私有的. 槽可以和信号连接在一起,在这种情况下,每当发射这个信号的信号,就会自动调 ...

  9. 如何获得 Qt窗口部件在主窗口中的位置--确定鼠标是否在某一控件上与在控件上的位置

    用Qt Creator 设计程序时,最方便的就是ui设计器,可以很容易的得到想要的布局. 但是这样自动布局带来的后果是很难知道窗口中某一部件在主窗口中的相对位置. 在处理子窗口鼠标事件时变的很麻烦.主 ...

随机推荐

  1. Git Learning Part II - Working locally

    file status life circle basic: modified:   Examples: untracked: unmodified: modified: Git branching ...

  2. AngularJs轻松入门

    AngularJs轻松入门系列博文:http://blog.csdn.net/column/details/angular.html AngularJs轻松入门(一)创建第一个应用 AngularJs ...

  3. Daily Build[called heart beat]

    ###Daily Build->Object File&Binary File->Deploymened on release server->BVT Automation. ...

  4. Mock Framework

    Typemock Isolator; Rhino Mocks; NMock; MS Fakes(has not same mechanism with NMock) Mock is usually u ...

  5. CUDA 编程实例:计算点云法线

    程序参考文章:http://blog.csdn.net/gamesdev/article/details/17535755  程序优化2 简介:CUDA ,MPI,Hadoop都是并行运算的工具.CU ...

  6. CSS读书笔记(1)---选择器和两列布局

    (1)CSS选择器优先权选择. 优先权从大到小的选择如下: 标有!important关键字声明的属性 HTML中的CSS样式属性 <div style="color:red" ...

  7. (转)shiro权限框架详解02-权限理论介绍

    http://blog.csdn.net/facekbook/article/details/54893042 权限管理解决方案 本文主要介绍权限管理的解决方法: 粗颗粒度和细颗粒度 基于url拦截 ...

  8. CGContext与上下文

    上下文指的是场景拥有的资源或属性. 上下文的操作包含上下文的设置: 和上下文的引用. 上下文是一个结构体. 主要包含结构体的设置和使用.

  9. 修改XtraMessageBox的内容字体大小

    修改XtraMessageBox的内容字体大小 public static DialogResult Show(UserLookAndFeel lookAndFeel, IWin32Window ow ...

  10. java equals的用法

    equals方法,用于比较两个对象是否相同,它其实就是使用两个对象的内存地址在比较.Object类中的equals方法内部使用的就是==比较运算符. package Xuexi; public cla ...