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

Divide a custom vertical layout by a Vertical splitter



  • Hi,

    I created my layout PlotVLayout inherited from abstract class QLayout
    PlotVLayout vertically sets QwtPlot widgets in a way that all canvases of these plots are one below another. So the main functionality of PlotVLayout is that it calculates the XY coordinates for each QwtPlot
    Now I would like to insert something like a QSplitter between QwtPlot to allow the user to change the height of each QwtPlot. The picture is attached.
    Is there a way to implement such functionality in my PlotVLayout?
    a5c3386f-9275-48a6-a59f-cca2efec49a9-image.png


  • Lifetime Qt Champion

    I don't know what is inside your code so I can't really comment,

    Why a reference rather than a const reference ?


  • Lifetime Qt Champion

    Hi,

    Something is not clear. You seem to have re-invented QVBoxLayout. Is that the case ?

    In any case, a layout does not have a visual presence, they just do positioning. QSplitter is a widget that seem to do what you want directly. Just use it with the right direction.



  • @SGaist no I dont reinvent QVBoxLayout.
    Lets suppose that we need two QwtPlot one below another but the canvas of each plot should have the same X-pos and different Y. So it is like two QwtPlot that share the same X-axis. Like in the picture:
    f794accb-6821-4500-81d2-0e04a73438ee-image.png


  • Lifetime Qt Champion

    I see. In that case you should make a widget that takes advantage of your custom layout and adds a control that works like QSplitter.

    You can check QSplitter's implementation.



  • @SGaist I encountered a strange problem...
    I have two custom layouts (PlotVLayout) and in private variable (QList<QwtPlot *> splitterPlotList;) I store list of widgets of both layouts.

    When I resize the mainwindow I can see that this list changes its size (count of elemetns) from 1 to 2 but it should always be 2 elements in list (I have qDebug() << splitterPlotList.count();)

    I set splitterPlotList by reference via:

    void PlotVLayout::setPlotList(QList<QwtPlot *> &splitterPlotList){
        this->splitterPlotList = splitterPlotList;
    }
    

    Why this happens?
    I suspect that when I resize the mainwindow my layouts work in parrallel threads and they are trying to achieve the same variable at the same time?


  • Lifetime Qt Champion

    I don't know what is inside your code so I can't really comment,

    Why a reference rather than a const reference ?



  • @SGaist I just changed to const List<> & and now it works :)
    thank you!


Log in to reply