先看一下效果截图:
mytest.pro //工程文件
QT += core gui widgets qml
TARGET = menu_test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
RESOURCES += \
images.qrc
OTHER_FILES +=
DISTFILES +=
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class MainWindow : public QMainWindow
{
Q_OBJECT
public slots:
void openFile();
void myTimeout();
void loadQml();
void saveTofile();
signals:
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void slotColorClick(int i);
private:
QTextEdit *txtTipComp;
QVBoxLayout *mainLayout;
QLabel *label;
QLabel *lab_pixmap;
QTimer *timer;
QGraphicsView* pView;
QQmlApplicationEngine engine;
QStringList strlist;
QSignalMapper signalMapper;
QLabel *label_color;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
const static char *lcolor0 = "color:white; background-color:#000000";
const static char *lcolor1 = "color:black; background-color:#ff0000";
const static char *lcolor2 = "color:black; background-color:#00ff00";
const static char *lcolor3 = "color:black; background-color:#00ffff";
const static char *lcolor4 = "color:white; background-color:#0000ff";
const static char *lcolor5 = "color:black; background-color:#ff00ff";
const static char *lcolor6 = "color:black; background-color:#ecae47";
const s