QDockWidget and Custom OpenGLWindow container malfunction

  • Hi Qt people!
    I'm having a little issue with QDockWidget. I'm working on a little CAD-like project using Qt and OpenGL. One of my windows contains QDockWidget with QTableWidget and QHorizontalLayout within. When I call the constructor of the window I fill the layout with QWidget used as container for instance that inherits from QOpenGLWindow class thats very similiar to class i found as Qt projects example codes.

    There are two problems:

    First problem is when the application starts, the OpenGLWindow container is resized to width 0. So you have to resize the dock widget manualy. I've tried to use size policy and min/max width and also geometry to adjust the size to optimum. But only setMinimumWidth affected the size. Using the minimumWidth as width setter is quite unsuitable. Also when I compile it with no minimumWidth set error occures:

    @setGeometry: Unable to set geometry 100x30+0+0 on RoomWindow/''. Resulting geometry: 104x30+0+0 (frame: 4, 23, 4, 4, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).@

    The second problem appeared when I added one more OpenGLWindow sharing the context of the first one. Both container widgets are now a little oversized at startup so they overlay the DockWidgets title and when I resize any widget within the main window they just resize to normal size like expected. It also seems, that the context isn't using the overlayed part because it's pure white and nothing renders to it.

    I've spend a lot of time trying to figure it out, but now I'm just desperate.The manual resizing doesn't really matter, but the overlay looks pretty bad so every advice is welcome.

    This is how the overlay looks like: !http://i61.tinypic.com/11jqh5f.png(Overlay)!

    I've also created stackoverflow question a while ago. But there's still no solution so I've decided to try it here.
    "Stackoverflow question":http://stackoverflow.com/questions/23031847/qt-expanding-layout-to-maximum-size-in-dock-widget?noredirect=1#comment35187981_23031847

    Any advice is welcome and Im looking forward to finally solving these problems. Cheers

  • Hi Lukas Vilim,

    Few basic question about Main window & doc widget placment.

    1. Have you used setCentralwidget api from QMainwindow to set your
      openGL widget container.. ?
    2. how you set the dock widget to QMainWindow... ?
    3. have you already reimplment the resizeevent for QMainwindow... ?
    4. have you used updateGL like api as per documentation ... in your
      customize openGL class ... ?

    share your QMainWindow constructor code where you fill those logic so it will be easy to understand your issue.

    I have also working on same kind of projects from same CAD domain so definately i will try my best to help you out in this problem.

    Prashant Moglaikar

  • Nice!

    1. I'm not using the setCentralWidget at all, I've created the dockWidget and layouts in designer and I created the container like that:

    @m_importerWindow = new ImporterWindow();
    m_importer_container = QWidget::createWindowContainer(m_importerWindow,ui->dockWidget_Importer,Qt::Window);
    m_importer_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    I've played with the createWindowContainer and tried to set different parents. This doesn't seem to change anything about the issue.

    1. DockWidget is created by the designer through ui file, so I think it has properly set the parent.
    2. I didn't! So maybe there will be some possible solution. But the QMainWindow is also generated by designer.
    3. I don' know what is the openGL like api in documentation I've read that I have to use QOpenGL* stuff, becose QGL* is going to be deprecated. I used a timer in my QOpenGLWindow class to set the repaint rate and then I every frame update my structures and repaint the scene. Header looks like this:

    class OpenGLWindow : public QWindow, protected QOpenGLFunctions
    explicit OpenGLWindow(QWindow *parent = 0);
    virtual ~OpenGLWindow();

    virtual void render() = 0;
    virtual void update() = 0;
    virtual void initialize() = 0;

    private slots:
    void renderer();

    static QOpenGLContext * m_context;
    static QTimer * m_animationTimer;



    (I've just picked up the importat)
    I'm inheriting from that class for both of my windows. I'm not really using any QGLWidgets. And when I watched some of the lectures from Dr. Sean Harmer I found out that declaring my own window with this kind of container workaround is perfectly fine.

    There is the example: "OpenGLWindow Example":http://qt-project.org/doc/qt-5/qtgui-openglwindow-example.html


  • Hi,

    // --- sample_ttr.pro ---


    Project created by QtCreator 2014-05-07T14:37:35


    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = sample_ttr
    TEMPLATE = app

    SOURCES += main.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui

    // --- mainwindow.h ---

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;

    class MainWindow : public QMainWindow

    explicit MainWindow(QWidget *parent = 0);

    Ui::MainWindow *ui;

    #endif // MAINWINDOW_H

    // --- mainwindow.cpp ---

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QTextEdit>
    #include <QHBoxLayout>
    #include <QVBoxLayout>
    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)
    QWidget *w = new QWidget();
    QTextEdit *t = new QTextEdit();
    QTextEdit *t1 = new QTextEdit();
    QTextEdit *t2 = new QTextEdit();
    QTextEdit *t3 = new QTextEdit();

    QHBoxLayout *h = new QHBoxLayout();
    QHBoxLayout *h1 = new QHBoxLayout();
    QVBoxLayout *h2 = new QVBoxLayout();


    delete ui;

    // --- main.cpp ---

    #include "mainwindow.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    MainWindow w;

    return a.exec&#40;&#41;;


    // --- mainwindow.ui ----

    I have just create simple default mainwidnow application in qt creator and add one docwidget through designer, after that i have drag & drop one list view into that dockwidget to dispaly dummy. so you can create this sample application at your end so you will be need to replace only above files...

    Now see if you run this sample application you will see the same application lauch like your screen shot at left side of dock widget you will get list view and at top you will see some dummy menu if you added from designer and at central location you will see 4 Text edit side by side.

    I guess from this you will get idea how to use setcentralwidget in QMainwindow constructor.

    So just tried with first simple widget then just replace with your opengl window object with them i guess you will get the solution hopefully....

    Prasahnt Moglaikar

  • Hi!
    I did some digging and setCentralWidget isn't kind of thing i want to use because my OpenGLWindow is located in the QDockWidget not in the MainWindow.
    And setting it as centralwidget seems like nonsense and also segfaults my app. :D

    So I'm definitely not going that way. But ty for option! Maybe I will give up on DockWidgets and just mix the stuff in the MainWindow.


Log in to reply