Search code examples
qtqt-designerqwt

Displaying qwt plot on UI form


I have my "MainWindonw" file and "Plot" file with a class to plot.

Currently I can display my Plot in two different ways:

  1. I can create in my UI form a widget and promote the Plot class. (in this way I can put my Plot in any place that I want)

  2. I can use the explicit declaration on code as:

    d_plot = new Plot( this );
    ....
    setCentralWidget( d_plot );
    

    However in this way I can't have control on my Plot, it just go to mainwindow

So my question is, how can I use something like the the code from item 2 to plot on my widget on UI form.

It's possible to do something like:

    setWidgetCreated (d_plot);

Solution

  • You must create dplot with the right widget as a parent. Supposing for example the container widget is a QGroupBox name gbox, you'll create it with this code:

    dplot = new Plot(ui->gbox);
    

    You'll likely need to apply some Layout. Have a look to the QT documentation for details. Some page you may find useful:

    http://doc.qt.io/qt-4.8/objecttrees.html

    http://doc.qt.io/qt-4.8/layout.html

    (By the way, I strongly prefer the first method, promoting the widget.)