1、icon图标资源来源网址:阿里巴巴矢量图
一个很好的图标资源网站
2、代码结构
图标:
产品包结构:
3、效果界面
4、source code
工程配置文件ImgProcressor.pro
#-------------------------------------------------
#
# Project created by QtCreator 2019-04-07T15:38:23
#
#-------------------------------------------------
QT += core gui
QT += printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ImgProcressor
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
imgprocressor.cpp \
showwidget.cpp
HEADERS += \
imgprocressor.h \
showwidget.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
头文件:
imgprocressor.h
#ifndef IMGPROCESSOR_H
#define IMGPROCESSOR_H
#include <QMainWindow>
#include <QString>
#include <QImage>
#include <QTextCharFormat>
class QMenu;
class ShowWidget;
class QAction;
class QToolBar;
class QLabel;
class QFontComboBox;
class QComboBox;
class QToolButton;
class QActionGroup;
class ImgProcessor : public QMainWindow
{
Q_OBJECT
public:
ImgProcessor(QWidget *parent = nullptr);
~ImgProcessor();
void createFont();
void createList();
void createActions();
void createMenus();
void createToolBars();
void loadFile(QString filename);
void mergeFormat(QTextCharFormat fmt);
protected slots:
void showNewFile();
void showOpenFile();
void showPrintText();
void showZoomIn();
void showZoomOut();
void showRotate90();
void showRotate270();
void showMirrorVectical();
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();
private:
void zoomImg(double xscale, double yscale);
void rotateImg(double angle);
private:
QMenu *fileMenu;
QMenu *zoomMenu;
QMenu *rotateMenu;
QMenu *mirrorMenu;
QImage img;
QString fileName;
ShowWidget *showWidget;
QAction *openFileAction;
QAction *newFileAction;
QAction *printTextAction;
QAction *exitAction;
QAction *copyAction;
QAction *cutAction;
QAction *pasteAction;
QAction *aboutAction;
QAction *zoomInAction;
QAction *zoomOutAction;
QAction *rotate90Action;
QAction *rotate270Action;
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 *underlineBtn;
QToolButton *italicBtn;
QToolButton *colorBtn;
QToolBar *fontToolBar;
QLabel *listLabel;
QComboBox *listComoBox;
QActionGroup *actGroup;
QAction *leftAction;
QAction *rightAction;
QAction *centerAction;
QAction *justifyAction;
QToolBar *listToolBar;
};
#endif // IMGPROCESSOR_H
showwidget.h
#ifndef SHOWWIDGET_H
#define SHOWWIDGET_H
#include <QWidget>
#include <QImage>
#include <QLabel>
#include <QTextEdit>
class QTextEdit;
class ShowWidget : public QWidget
{
Q_OBJECT
public:
explicit ShowWidget(QWidget *parent = nullptr);
QImage img;
QLabel *imageLabel;
QTextEdit *text;
signals:
public slots:
};
#endif // SHOWWIDGET_H
实现文件:
imgprocressor.cpp
#include "imgprocressor.h"
#include "showwidget.h"
#include <QAction>
#include <QIcon>
#include <QMenu>
#include <QToolBar>
#include <QApplication>
#include <QFileDialog>
#include <QFile>
#include <QTextStream>
#include <QPrintDialog>
#include <QPrinter>
#include <QMatrix>
#include <QPixmap>
#include <QLabel>
#include <QFontComboBox>
#include <QTextEdit>
#include <QTextDocument>
#include <QComboBox>
#include <QFontDatabase>
#include <QToolButton>
#include <QTextCharFormat>
#include <QTextCursor>
#include <QColorDialog>
#include <QColor>
#include <QActionGroup>
#include <QTextBlockFormat>
#include <QTextListFormat>
#include <QTextList>
ImgProcessor::ImgProcessor(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle(tr("Easy Word"));
showWidget = new ShowWidget(this);
setCentralWidget(showWidget);
createFont();
createList();
createActions();
createMenus();
createToolBars();
if (img.load("icon/image.png"))
{
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
}
void ImgProcessor::createFont()
{
fontLabel1 = new QLabel(tr("font: "));
fontCombobox = new QFontComboBox;
fontCombobox->setFontFilters(QFontComboBox::ScalableFonts);
connect(fontCombobox, SIGNAL(activated(QString)), this, SLOT(showFontCombobox(QString)));
fontLabel2 = new QLabel(tr("word size: "));
sizeCombobox = new QComboBox;
connect(sizeCombobox, SIGNAL(activated(QString)), this, SLOT(showSizeSpinBox(QString)));
QFontDatabase db;
foreach(int size, db.standardSizes())
sizeCombobox->addItem(QString::number(size));
boldBtn = new QToolButton;
boldBtn->setIcon(QIcon("icon/bold.png"));
boldBtn->setCheckable(true);
connect(boldBtn, SIGNAL(clicked()), this, SLOT(showBoldBtn()));
italicBtn = new QToolButton;
italicBtn->setIcon(QIcon("icon/italic.png"));
italicBtn->setCheckable(true);
connect(italicBtn, SIGNAL(clicked()), this, SLOT(showItalicBtn()));
underlineBtn = new QToolButton;
underlineBtn->setIcon(QIcon("icon/underline.png"));
underlineBtn->setCheckable(true);
connect(underlineBtn, SIGNAL(clicked()), this, SLOT(showUnderlineBtn()));
colorBtn = new QToolButton;
colorBtn->setIcon(QIcon("icon/color.png"));
colorBtn->setCheckable(true);
connect(colorBtn, SIGNAL(clicked()), this, SLOT(showColorBtn()));
connect(showWidget->text, SIGNAL(currentCharFormatChanged(QTextCharFormat&)),
this, SLOT(showCurrentFormatChanged(QTextCharFormat&)));
}
void ImgProcessor::createList()
{
listLabel = new QLabel(tr("sort"));
listComoBox = new QComboBox;
listComoBox->addItem("Standard");
listComoBox->addItem("OTextListFormat::ListDisc");
listComoBox->addItem("QTextListFormat::ListCircle");
listComoBox->addItem("QTextListFormat::ListSquare");
listComoBox->addItem("OTextListFormat::ListDecimal");
listComoBox->addItem("QTextListFormat::ListLowerAlpha");
listComoBox->addItem("QTextListFormat::ListUpperAlpha");
listComoBox->addItem("QTextListFormat::ListLowerRoman");
listComoBox->addItem("QTextListFormat::ListUpperRoman");
connect(listComoBox, 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()));
}
void ImgProcessor::createActions()
{
// open action
openFileAction = new QAction(QIcon("icon/open.png"), tr("open"), this);
openFileAction->setShortcut(tr("Ctrl+O"));
openFileAction->setStatusTip(tr("open a Image"));
connect(openFileAction, SIGNAL(triggered()), this, SLOT(showOpenFile()));
// new action
newFileAction = new QAction(QIcon("icon/new.png"), tr("new"), this);
newFileAction->setShortcut(tr("Ctrl+N"));
newFileAction->setStatusTip(tr("create a Image"));
connect(newFileAction, SIGNAL(triggered()), this, SLOT(showNewFile()));
// exit action
exitAction = new QAction(tr("exit"), this);
exitAction->setShortcut(tr("Ctrl+Q"));
exitAction->setStatusTip(tr("exit program"));
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
// copy action
copyAction = new QAction(QIcon("icon/copy.png"), tr("copy"), this);
copyAction->setShortcut(tr("Ctrl+C"));
copyAction->setStatusTip(tr("copy a Image"));
connect(copyAction, SIGNAL(triggered()), showWidget->text, SLOT(copy()));
// cut action
cutAction = new QAction(QIcon("icon/cut.png"), tr("cut"), this);
cutAction->setShortcut(tr("Ctrl+X"));
cutAction->setStatusTip(tr("cut a Image"));
connect(copyAction, SIGNAL(triggered()), showWidget->text, SLOT(cut()));
// paste action
pasteAction = new QAction(QIcon("icon/paste.png"), tr("paste"), this);
pasteAction->setShortcut(tr("Ctrl+V"));
pasteAction->setStatusTip(tr("parse a Image"));
connect(pasteAction, SIGNAL(triggered()), showWidget->text, SLOT(paste()));
// about action
aboutAction = new QAction(tr("about"), this);
// connect(aboutAction, SIGNAL(triggered()), this, SLOT(QApplication::aboutQt()));
// print text action
printTextAction = new QAction(QIcon("icon/print.png"), tr("print"), this);
printTextAction->setStatusTip(tr("print a text"));
connect(printTextAction, SIGNAL(triggered()), this, SLOT(showPrintText()));
// zoom in action
zoomInAction = new QAction(QIcon("icon/zoom-in.png"), tr("zoom-in"), this);
zoomInAction->setStatusTip(tr("zoom in a image"));
connect(zoomInAction, SIGNAL(triggered()), this, SLOT(showZoomIn()));
// zoom out action
zoomOutAction = new QAction(QIcon("icon/zoom-out.png"), tr("zoom-out"), this);
zoomOutAction->setStatusTip(tr("zoom-out a image"));
connect(zoomOutAction, SIGNAL(triggered()), this, SLOT(showZoomOut()));
// rotate action
rotate90Action = new QAction(QIcon("icon/rotate-right.png"), tr("rotate 90"), this);
rotate90Action->setStatusTip(tr("rotate 90 a image"));
connect(rotate90Action, SIGNAL(triggered()), this, SLOT(showRotate90()));
rotate270Action = new QAction(QIcon("icon/rotate-left.png"), tr("rotate 270"), this);
rotate270Action->setStatusTip(tr("rotate 270 a image"));
connect(rotate270Action, SIGNAL(triggered()), this, SLOT(showRotate270()));
// mirror action
mirrorVerticalAction = new QAction(QIcon("icon/vertical-mirror.png"), tr("vertical mirror"), this);
mirrorVerticalAction->setStatusTip(tr("vertical mirror to a image"));
connect(mirrorVerticalAction, SIGNAL(triggered()), this, SLOT(showMirrorVectical()));
mirrorHorizontalAction = new QAction(QIcon("icon/horizontal-mirror.png"), tr("horizontal mirror"), this);
mirrorHorizontalAction->setStatusTip(tr("horizontal mirror to a image"));
connect(mirrorHorizontalAction, SIGNAL(triggered()), this, SLOT(showMirrorHorizontal()));
// undo & redo action
undoAction = new QAction(QIcon("icon/undo.png"), tr("undo"), this);
connect(undoAction, SIGNAL(triggered()), showWidget->text, SLOT(undo()));
redoAction = new QAction(QIcon("icon/redo.png"), tr("redo"), this);
connect(redoAction, SIGNAL(triggered()), showWidget->text, SLOT(redo()));
actGroup = new QActionGroup(this);
leftAction = new QAction(QIcon("icon/left.png"), "left alignment", actGroup);
leftAction->setCheckable(true);
rightAction = new QAction(QIcon("icon/right.png"), "right alignment", actGroup);
rightAction->setCheckable(true);
centerAction = new QAction(QIcon("icon/center.png"), "center alignment", actGroup);
centerAction->setCheckable(true);
justifyAction = new QAction(QIcon("icon/justify.png"), "justify alignment", actGroup);
justifyAction->setCheckable(true);
connect(actGroup, SIGNAL(triggered(QAction*)), this, SLOT(showAlignment(QAction*)));
}
void ImgProcessor::createMenus()
{
fileMenu = new QMenu(tr("file"), this);
fileMenu->addAction(openFileAction);
fileMenu->addAction(newFileAction);
fileMenu->addAction(printTextAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
zoomMenu = new QMenu(tr("edit"), this);
zoomMenu->addAction(copyAction);
zoomMenu->addAction(cutAction);
zoomMenu->addAction(pasteAction);
zoomMenu->addAction(aboutAction);
zoomMenu->addSeparator();
zoomMenu->addAction(zoomInAction);
zoomMenu->addAction(zoomOutAction);
rotateMenu = new QMenu(tr("rotate"), this);
rotateMenu->addAction(rotate90Action);
rotateMenu->addAction(rotate270Action);
mirrorMenu = new QMenu(tr("mirror"), this);
mirrorMenu->addAction(mirrorVerticalAction);
mirrorMenu->addAction(mirrorHorizontalAction);
}
void ImgProcessor::createToolBars()
{
fileTool = addToolBar("file");
fileTool->addAction(openFileAction);
fileTool->addAction(newFileAction);
fileTool->addAction(printTextAction);
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(rotate270Action);
mirrorTool = addToolBar("mirror");
mirrorTool->addAction(mirrorVerticalAction);
mirrorTool->addAction(mirrorHorizontalAction);
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(listComoBox);
listToolBar->addSeparator();
listToolBar->addActions(actGroup->actions());
}
void ImgProcessor::showNewFile()
{
ImgProcessor *newImgProcessor = new ImgProcessor;
newImgProcessor->show();
}
void ImgProcessor::showOpenFile()
{
fileName = QFileDialog::getOpenFileName(this);
if (not fileName.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::showZoomIn()
{
zoomImg(2, 2);
}
void ImgProcessor::showZoomOut()
{
zoomImg(0.5, 0.5);
}
void ImgProcessor::zoomImg(double xscale, double yscale)
{
if (img.isNull())
return;
QMatrix martix;
martix.scale(xscale, yscale);
img = img.transformed(martix);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
void ImgProcessor::showRotate90()
{
rotateImg(90);
}
void ImgProcessor::showRotate270()
{
rotateImg(270);
}
void ImgProcessor::rotateImg(double angle)
{
if (img.isNull())
return ;
QMatrix matrix;
matrix.rotate(angle);
img = img.transformed(matrix);
showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
void ImgProcessor::showMirrorVectical()
{
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 fmt)
{
QTextCursor cursor = showWidget->text->textCursor();
if (!cursor.hasSelection())
{
cursor.select(QTextCursor::WordUnderCursor);
}
cursor.mergeCharFormat(fmt);
showWidget->text->mergeCurrentCharFormat(fmt);
}
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::showList(int index)
{
QTextCursor cursor = showWidget->text->textCursor();
if (index)
{
QTextListFormat::Style style = QTextListFormat::ListDisc;
switch (index)
{
default:
case 1:
style = QTextListFormat::ListDisc; break;
case 2:
style = QTextListFormat::ListCircle; break;
case 3:
style = QTextListFormat::ListSquare; break;
case 4:
style = QTextListFormat::ListDecimal; break;
case 5:
style = QTextListFormat::ListLowerAlpha; break;
case 6:
style = QTextListFormat::ListUpperAlpha; break;
case 7:
style = QTextListFormat::ListLowerRoman; break;
case 8:
style = QTextListFormat::ListUpperRoman; break;
}
cursor.beginEditBlock();
QTextBlockFormat blockFmt = cursor.blockFormat();
QTextListFormat listFmt;
if (cursor.currentList())
{
listFmt = cursor.currentList()->format();
}
else
{
listFmt.setIndent(blockFmt.indent() + 1);
blockFmt.setIndent(0);
cursor.setBlockFormat(blockFmt);
}
listFmt.setStyle(style);
cursor.createList(listFmt);
cursor.endEditBlock();
}
else
{
QTextBlockFormat bfmt;
bfmt.setObjectIndex(-1);
cursor.mergeBlockFormat(bfmt);
}
}
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);
}
ImgProcessor::~ImgProcessor()
{
if (fileMenu) { delete fileMenu; fileMenu = nullptr; }
if (zoomMenu) { delete zoomMenu; zoomMenu = nullptr; }
if (rotateMenu) { delete rotateMenu; rotateMenu = nullptr; }
if (mirrorMenu) { delete mirrorMenu; mirrorMenu = nullptr; }
if (showWidget) { delete showWidget; showWidget = nullptr; }
if (openFileAction) { delete openFileAction; openFileAction = nullptr; }
if (newFileAction) { delete newFileAction; newFileAction = nullptr; }
if (printTextAction) { delete printTextAction; printTextAction = nullptr; }
if (exitAction) { delete exitAction; exitAction = nullptr; }
if (copyAction) { delete copyAction; copyAction = nullptr; }
if (cutAction) { delete cutAction; cutAction = nullptr; }
if (pasteAction) { delete pasteAction; pasteAction = nullptr; }
if (aboutAction) { delete aboutAction; aboutAction = nullptr; }
if (zoomInAction) { delete zoomInAction; zoomInAction = nullptr; }
if (zoomOutAction) { delete zoomOutAction; zoomOutAction = nullptr; }
if (rotate90Action) { delete rotate90Action; rotate90Action = nullptr; }
if (rotate270Action) { delete rotate270Action; rotate270Action = nullptr; }
if (mirrorVerticalAction) { delete mirrorVerticalAction; mirrorVerticalAction = nullptr; }
if (mirrorHorizontalAction) { delete mirrorHorizontalAction; mirrorHorizontalAction = nullptr; }
if (undoAction) { delete undoAction; undoAction = nullptr; }
if (redoAction) { delete redoAction; redoAction = nullptr; }
if (fileTool) { delete fileTool; fileTool = nullptr; }
if (zoomTool) { delete zoomTool; zoomTool = nullptr; }
if (rotateTool) { delete rotateTool; rotateTool = nullptr; }
if (mirrorTool) { delete mirrorTool; mirrorTool = nullptr; }
if (doToolBar) { delete doToolBar; doToolBar = nullptr; }
if (fontLabel1) { delete fontLabel1; fontLabel1 = nullptr; }
if (fontCombobox) { delete fontCombobox; fontCombobox = nullptr; }
if (fontLabel2) { delete fontLabel2; fontLabel2 = nullptr; }
if (sizeCombobox) { delete sizeCombobox; sizeCombobox = nullptr; }
if (boldBtn) { delete boldBtn; boldBtn = nullptr; }
if (underlineBtn) { delete underlineBtn; underlineBtn = nullptr; }
if (italicBtn) { delete italicBtn; italicBtn = nullptr; }
if (colorBtn) { delete colorBtn; colorBtn = nullptr; }
if (fontToolBar) { delete fontToolBar; fontToolBar = nullptr; }
}
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);
}
主程序:main.cpp
#include "imgprocressor.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFont f("ZYSong18030", 12);
a.setFont(f);
ImgProcessor w;
w.show();
return a.exec();
}