qml写控件widget调用_Qt简单的控件运用及加载qml文件混合编程

本文展示了如何在Qt环境中结合QML和Widget控件进行混合编程,通过创建一个主窗口应用,实现了QML加载、颜色切换、文件操作等功能。主要涉及QMenu、QToolBar、QTextEdit、QGraphicsView等组件的使用,并通过信号槽机制实现QML与C++的交互。
摘要由CSDN通过智能技术生成

先看一下效果截图:

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值