Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Resize WindowContainer in Dockwidget



  • Hey,

    I have a QDockWidget that contains a WindowContainer for a Q3DSurface. My problem is that if I change the size of the dockWidget during runtime, the size of the Q3DSurface stays constant.

    main {
        ....
        QDockWidget *dock = new QDockWidget();
        someParent->addDockWidget(Qt::DockWidgetArea::RightDockWidgetArea, dock);
    }
    

    In the class DataVisualizer:

    DataVisualizer::DataVisualizer(QWidget *parent) : QWidget(parent) {
    
    	this->setContentsMargins(QMargins(0, 20, 0, 0));
    	QtDataVisualization::Q3DSurface graph = new QtDataVisualization::Q3DSurface();
    	QWidget *container = QWidget::createWindowContainer(graph);
    	
    
    	QSize screenSize = graph->screen()->size();
    	container->setMinimumSize(QSize(screenSize.width()/4, screenSize.height() /2));
    	container->setMaximumSize(screenSize);
    
    	QVBoxLayout *hLayout = new QVBoxLayout(this);
    	hLayout->addWidget(container, 0);
    
    }
    

    I hope you have enough information. Thank you for intrest.

    Best regards

    Nertunt


  • Lifetime Qt Champion

    Hi,

    What version of Qt are you using ?
    On what platform ?

    Can you provide a complete minimal example showing that behaviour ?



  • Hey,

    I use QT 5.11. with Visual Studio 2017 and Windows 10. Below a minimal working example.

    #include <QtWidgets/QApplication>
    #include "DataVisualizerWidget.hpp"
    
    
    int main(int argc, char *argv[]) {
    	QApplication app(argc, argv);
    	QMainWindow window;
    	
    	QDockWidget *dock = new QDockWidget();
    	DataVisualizerWidget visualizer = new DataVisualizerWidget(dock);
    	window.addDockWidget(Qt::DockWidgetArea::RightDockWidgetArea, dock);
    
    	window.show();
    	return app.exec();
    }
    

    The header file for DataVisualizationWidget:

    #pragma once
    #include <QtWidgets/QWidget>
    
    class QResizeEvent;
    
    class MicroVisualizerWidget : public QWidget {
    	Q_OBJECT
    
    public:
    	DataVisualizerWidget(QWidget *parent);
    };
    

    The source file for DataVisualizationWidget:

    #include "DataVisualizerWidget.hpp"
    
    #include <QVBoxLayout>
    #include <QtGui/QScreen>
    #include <QtDataVisualization\q3dsurface.h>
    
    DataVisualizerWidget::DataVisualizerWidget(QWidget *parent) : QWidget(parent) {
    	
            //definining the widget
    	 QtDataVisualization::Q3DSurface *graph = new QtDataVisualization::Q3DSurface();
    	QWidget *container = QWidget::createWindowContainer(graph);
    	QSize screenSize = graph->screen()->size();
    	container->setMinimumSize(QSize(screenSize.width()/4, screenSize.height()/3));
    	container->setMaximumSize(screenSize);
    	QVBoxLayout *hLayout = new QVBoxLayout(this);
    	hLayout->addWidget(container, 0);
    
            // Setting the values for graph
    	QtDataVisualization::QSurfaceDataArray *data = new QtDataVisualization::QSurfaceDataArray;
    	QtDataVisualization::QSurfaceDataRow *dataRow1 = new QtDataVisualization::QSurfaceDataRow;
    	QtDataVisualization::QSurfaceDataRow *dataRow2 = new QtDataVisualization::QSurfaceDataRow;
    	
    	*dataRow1 << QVector3D(0.0f, 0.1f, 0.5f) << QVector3D(1.0f, 0.5f, 0.5f);
    	*dataRow2 << QVector3D(0.0f, 1.8f, 1.0f) << QVector3D(1.0f, 1.2f, 1.0f);
    	*data << dataRow1 << dataRow2;
    
    	QtDataVisualization::QSurface3DSeries *series = new QtDataVisualization::QSurface3DSeries;
    	series->dataProxy()->resetArray(data);
    	graph->addSeries(series);
    }
    

    I hope this helps. Thank you.

    Nertunt


Log in to reply