[SOLVED]can anyone tell me how to scale qwtPlot in a window
-
Hello, I'm using qwt to help my work, but I meet some troubles.
I put a tabWidget in MainWindow, and put qwtPlot in each tab, when I scale the MainWindow, the tab can scale with the window, but the qwtPlot can't scale together, can anybody tell me how to align them?
-
The QwtPlot inside the tab, is it inside a layout?
Thus you should have the Tab, then a layout and in the layout the QwtPlot?For me this is working very well to scale the widget
-
sorry Badger, I didn't apply any layout in the mainwindows or the tabwidget.
the tabwidget is the centerwidget, and the qwtplot is now the only item inside the tab, I used
@new qwtPlot(tabwidgets->widget(0))@
to attach the qwtPlot to tabWidget. it can display, but can't scale with the mainwindow together
-
That might be the problem, what I normally do if I create widgets at run time is the following:
@
/* Check if the widget that should contain the new widget have a layout, if it does have one, delete and create a new one depending on our needs. /
if(tabwidgets->widget(0)->layout() != NULL) {
delete tabwidgets->widget(0)->layout();
}
/ Create a Horizontal, Vertical or any other required layout for the widget*/
QHBoxLayout* myLayout= new QHBoxLayout(tabwidgets->widget(0));
/* Create the plot and add it to the layout */
myLayout->addWidget(new qwtPlot(NULL));
@This way the plot is in the layout of the widget and it will resize with the widget.
Instead of deleting the layout one can also just get the current one and add the plot to it, but then you are not sure what type of layout it is.
Hope this helps and is not too late :)
Edit: added missing bracket to the code
-
thank you, it works well,
at first it warns qwtPlot is not a QWidget, but I add positions like
@myLayout->addWidget(new qwtPlot(tabwidgets->widget(0)), 0, 1);@
it works
-
I am glad that it works.
Just a comment, from my understanding, when adding the widget to the layout, the layout will take ownership of the widget. If this is correct then you do not need to pass the tabwidgets->widget(0) to the constructor of the plot, you can just pass NULL because it will in any case transfer the ownership to the layout as soon as it is added.
Have a good day :)