![](/img/trans.png)
[英]Receiving mouse EnterEvent and LeaveEvent on multiple popup widgets in Qt5
[英]QT5 - multiple OpenGL widgets in the same window
我已經使用OpenGL ES開發了基本的圖形引擎監視應用程序。 它繪制基本的2D幾何。 我有興趣將其移植到QT5以實現跨平台可比性。
我想將每個壓力表變成具有其自身信號和插槽的單個小部件。 QT提供了一個很好的示例 ,說明如何制作OpenGL小部件。 但是,此方法為每個小部件創建一個新窗口。 是否有一種方法可以使每個量規成為其自己的小部件,並將它們全部繪制在同一窗口中?
QOpenGLWidget是一個小部件,因此您可以將其放置在另一個小部件中,在創建單個小部件的示例中,這就是窗口。 您可以創建一些QMainWindow,QDialog或QWidget並將它們放置在QOpenGLWidget中,以下是如何執行此操作的示例,只需將此main替換為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();
}
輸出:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.