是否有适用于QT5的Designer OpenGL小部件?

Mik*_*ail 4 opengl qt-creator qt5

我正在将一些代码从FLTK迁移到QT5,我似乎无法在与OpenGL上下文对应的图形设计中获得一个小部件?这样的小部件是否存在?

我从官方来源构建了QT,使用OpenGL选项定位VS2012x64,并尝试添加QT += opengl到我的project.pro文件中.

dat*_*olf 5

Qt有QGLWidget,但你不应该直接在Designer中使用它.相反,您应该在您希望OpenGL小部件出现的位置放置一个布局.然后你继承QGLWidget,因为你必须覆盖paintGL函数来绘制一些东西.然后在setupUI()调用之后,您实例化自定义GL小部件并将其添加到您放置在设计器中的布局中layoutinstance->addWidget(…)

因评论而更新

mainwindow.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>335</width>
    <height>191</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QVBoxLayout" name="verticalLayout_2">
    <item>
     <layout class="QVBoxLayout" name="verticalLayout"/>
    </item>
   </layout>
  </widget>
  <action name="actionQuit">
   <property name="text">
    <string>&amp;Quit</string>
   </property>
  </action>
 </widget>
 <resources/>
 <connections/>
</ui>
Run Code Online (Sandbox Code Playgroud)

myglwidget.hh

#include <QGLWidget>

class MyGLWidget : public QGLWidget
{ //...
};
Run Code Online (Sandbox Code Playgroud)

mainwindow.hh

#include <QMainWindow>

#include "myglwidget.hh"
#include "mainwindow_ui.hh" // generated by uic

class MainWindow : public QMainWindow, Ui_MainWindow
{

    MainWindow(QObject *parent = NULL) : 
        QMainWindow(parent)
    { // one would implement the constructor in the .cc file of course
        this->setupUi(this);

        glwidget = new MyGLWidget(this);

        // using the this pointer to emphase the location of the
        // member variable used.
        // NOTE: In the UI we defined a layout names verticalLayout
        this->verticalLayout->addWidget(glwidget);
    }

protected:
    MyGLWidget *glwidget;
};
Run Code Online (Sandbox Code Playgroud)

关键是,你只使用一个布局.UI中的普通常规布局,您可以向其添加派生的OpenGL窗口小部件.ui没有变形,没有促销!