1. win32主窗口修改参数 及增加窗口类的头文件(mainClass.h)
#include <QtWidgets/QApplication>
//#include <QtCore/QCoreApplication>
#include "mainClass.h"
int main(int argc, char *argv[])
{
//QCoreApplication a(argc, argv);
QApplication a(argc, argv);
QFont font("ZYSong18030", 12);
a.setFont(font);
mainClass *myClass = new mainClass(0);
myClass->initDlg();
return a.exec();
}
2. 创建QT类:
1. 头文件
#pragma once
#include <QObject>
#include "QtWidgets/qmainwindow.h"
#include "QtWidgets/qsplitter.h"
#include "QtCore/qobject.h"
#include "QtWidgets/qlabel.h"
#include "QtWidgets/qtextedit.h"
#include "QtWidgets/qpushbutton.h"
#include "QtCore/qdebug.h"
#include "opencvhead.h"
#include "hikvisonMyCamera.h"
#include "myTcpServer.h"
#ifdef _DEBUG
#pragma comment(lib, "Qt5Networkd.lib")
#pragma comment(lib, "Qt5Cored.lib")
#pragma comment(lib, "Qt5Guid.lib")
#pragma comment(lib, "Qt5Widgetsd.lib")
#else
#pragma comment(lib, "Qt5Network.lib")
#pragma comment(lib, "Qt5Core.lib")
#pragma comment(lib, "Qt5Gui.lib")
#pragma comment(lib, "Qt5Widgets.lib")
#endif
class mainClass : public QObject
{
Q_OBJECT
public:
mainClass(QObject *parent);
~mainClass();
public:
void initDlg();
void childDlg();
void LogTxt(QString szMsg);
Mat getImg();
private slots:
void openCam();
void run();
void manual();
private:
ChikvisionMyCamera *myCamera;
int nOpen;
int nIndex;
#pragma region [dlg]
private:
//主界面
QSplitter *splitterMain;
//被左右分隔
QSplitter *splitterLeft;
//操作界面对话框
QWidget *widget;
//相机显示
QLabel *Cam;
//日志显示控件
QTextEdit *logDlg;
//按钮
QPushButton *camBtn;
QPushButton *runBtn;
QPushButton *manualBtn;
#pragma endregion [dlg]
};
2. class内容
#include "mainClass.h"
void mainClass::initDlg()
{
splitterMain = new QSplitter(Qt::Horizontal);
splitterMain->setGeometry(150, 150, 1200, 800);
splitterLeft = new QSplitter(Qt::Horizontal, splitterMain);//::Vertical
splitterMain->addWidget(splitterLeft);
widget = new QWidget;
widget->setWindowFlags(Qt::Window);
splitterMain->addWidget(widget);
Cam = new QLabel;
Cam->setFrameShape(QFrame::Box);
splitterLeft->addWidget(Cam);
//分离器被设置为2:1
QList<int> q = { 20,10 };
splitterMain->setSizes(q);
//设置边界颜色
splitterMain->setStyleSheet("QSplitter::handle {background-color:blue}");
//固定分离器分割线
QSplitterHandle *splitterMainHandle = splitterMain->handle(1);
if (splitterMainHandle)
splitterMainHandle->setDisabled(true);
this->setParent(splitterMain);
splitterMain->setWindowTitle(QObject::tr("main"));
splitterMain->show();
childDlg();
}
void mainClass::childDlg()
{
camBtn = new QPushButton(QObject::tr("打开相机"), widget);
camBtn->setGeometry(10, 10, 80, 40);
camBtn->show();
runBtn = new QPushButton(QObject::tr("自动"), widget);
runBtn->setGeometry(10, 340, 80, 40);
runBtn->show();
manualBtn = new QPushButton(QObject::tr("手动"), widget);
manualBtn->setGeometry(120, 340, 80, 40);
manualBtn->show();
//日志显示位置
logDlg = new QTextEdit(widget);
logDlg->setGeometry(0, 400, 400, 400);
logDlg->show();
//btn连接
connect(camBtn, SIGNAL(clicked()), this, SLOT(openCam()) );
connect(runBtn, SIGNAL(clicked()), this, SLOT(run()) );
connect(manualBtn, SIGNAL(clicked()), this, SLOT(manual()) );
}
来源:https://blog.csdn.net/zxl2712028/article/details/100525042