I have developed a basic graphical engine monitoring application using OpenGL ES. It draws basic 2D geometry. I am interested in porting this to QT5 for the cross-platform comparability.
我使用OpenGL ES开发了一个基本的图形引擎监控应用程序。它绘制基本的2D几何体。我有兴趣将其移植到QT5以获得跨平台的可比性。
I want to turn each gauge into an individual widget with it's own signals and slots. QT provides a nice example of how to make an OpenGL widget. However, this method makes a new window for each widget. It there a method to make each gauge it's own widget and draw them all in the same window?
我想把每个仪表变成一个单独的小部件,它有自己的信号和插槽。 QT提供了一个如何制作OpenGL小部件的很好的例子。但是,此方法为每个窗口小部件创建一个新窗口。它有一种方法,使每个测量它自己的小部件,并在同一窗口中绘制它们?
Here is a picture of application for reference.
这是申请参考的图片。
1 个解决方案
#1
0
QOpenGLWidget is a widget so you can place it inside another widget, in the example when creating a single widget this will be the window. You can create some QMainWindow, QDialog or QWidget and place within them a QOpenGLWidget, the following is an example of how to do it, just replace this main to the main example:
QOpenGLWidget是一个小部件,因此您可以将其放在另一个小部件中,在创建单个小部件的示例中,这将是窗口。您可以创建一些QMainWindow,QDialog或QWidget,并在其中放置一个QOpenGLWidget,以下是如何执行此操作的示例,只需将此main替换为主示例:
#include <QApplication>
#include <QDialog>
#include <QLabel>
#include <QSurfaceFormat>
#include <QVBoxLayout>
#ifndef QT_NO_OPENGL
#include "mainwidget.h"
#endif
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSurfaceFormat format;
format.setDepthBufferSize(24);
QSurfaceFormat::setDefaultFormat(format);
app.setApplicationName("cube");
app.setApplicationVersion("0.1");
#ifndef QT_NO_OPENGL
QDialog w;
QHBoxLayout *lay = new QHBoxLayout(&w);
QHBoxLayout *hlay = new QHBoxLayout;
hlay->addWidget(new MainWidget(&w));
hlay->addWidget(new MainWidget(&w));
QVBoxLayout *vlay = new QVBoxLayout;
vlay->addLayout(hlay);
vlay->addWidget(new MainWidget(&w));
lay->addWidget(new MainWidget(&w));
lay->addLayout(vlay);
w.resize(640, 480);
w.show();
#else
QLabel note("OpenGL Support required");
note.show();
#endif
return app.exec();
}
Output:
#1
0
QOpenGLWidget is a widget so you can place it inside another widget, in the example when creating a single widget this will be the window. You can create some QMainWindow, QDialog or QWidget and place within them a QOpenGLWidget, the following is an example of how to do it, just replace this main to the main example:
QOpenGLWidget是一个小部件,因此您可以将其放在另一个小部件中,在创建单个小部件的示例中,这将是窗口。您可以创建一些QMainWindow,QDialog或QWidget,并在其中放置一个QOpenGLWidget,以下是如何执行此操作的示例,只需将此main替换为主示例:
#include <QApplication>
#include <QDialog>
#include <QLabel>
#include <QSurfaceFormat>
#include <QVBoxLayout>
#ifndef QT_NO_OPENGL
#include "mainwidget.h"
#endif
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSurfaceFormat format;
format.setDepthBufferSize(24);
QSurfaceFormat::setDefaultFormat(format);
app.setApplicationName("cube");
app.setApplicationVersion("0.1");
#ifndef QT_NO_OPENGL
QDialog w;
QHBoxLayout *lay = new QHBoxLayout(&w);
QHBoxLayout *hlay = new QHBoxLayout;
hlay->addWidget(new MainWidget(&w));
hlay->addWidget(new MainWidget(&w));
QVBoxLayout *vlay = new QVBoxLayout;
vlay->addLayout(hlay);
vlay->addWidget(new MainWidget(&w));
lay->addWidget(new MainWidget(&w));
lay->addLayout(vlay);
w.resize(640, 480);
w.show();
#else
QLabel note("OpenGL Support required");
note.show();
#endif
return app.exec();
}
Output: