Originally Posted by
Uwe
Or even better: try overload QwtPlot::updateLayout and put your code there. If this is possible you don't need to take care of when to call what.
Uwe
I have been trying to do this by creating a class that inherits from QwtPlot and by overriding the virtual function updateLayout. I think everythink would work fine if there would be a way of making the plot fill the whole widget! I mean, before having this derived class (plotclass.h), I would go to the QtDesigner, right click over the selected widget and choose the option "Promote to" and then "QwtPlot" and everything would be okay since the plot would fill the entire widget space.
The code for my derived class is:
#include "plotclass.h"
#include "qwt_scale_widget.h"
plotClass
::plotClass(QWidget *parent
):{
;
}
void plotClass::updateLayout()
{
int width_yRight;
int height_xBottom;
int width_yLeft;
if(this
->axisEnabled
(QwtPlot::yRight)) width_yRight
= this
->axisWidget
(QwtPlot::yRight)->width
();
else
width_yRight = 0;
if(this
->axisEnabled
(QwtPlot::yLeft) && this
->axisEnabled
(QwtPlot::xBottom)) {
height_xBottom
= this
->axisWidget
(QwtPlot::xBottom)->height
();
width_yLeft
= this
->axisWidget
(QwtPlot::yLeft)->width
();
}
else
{
height_xBottom = 0;
width_yLeft = 0;
}
int h = this->height();
int w = (h-height_xBottom) + (width_yLeft+width_yRight);
this->resize(w,h);
this->move((this->parentWidget()->width()-w)/2,(this->parentWidget()->height()-h)/2);
}
#include "plotclass.h"
#include "qwt_scale_widget.h"
plotClass::plotClass(QWidget *parent):
QwtPlot(parent)
{
;
}
void plotClass::updateLayout()
{
int width_yRight;
int height_xBottom;
int width_yLeft;
if(this->axisEnabled(QwtPlot::yRight))
width_yRight = this->axisWidget(QwtPlot::yRight)->width();
else
width_yRight = 0;
if(this->axisEnabled(QwtPlot::yLeft) && this->axisEnabled(QwtPlot::xBottom))
{
height_xBottom = this->axisWidget(QwtPlot::xBottom)->height();
width_yLeft = this->axisWidget(QwtPlot::yLeft)->width();
}
else
{
height_xBottom = 0;
width_yLeft = 0;
}
int h = this->height();
int w = (h-height_xBottom) + (width_yLeft+width_yRight);
this->resize(w,h);
this->move((this->parentWidget()->width()-w)/2,(this->parentWidget()->height()-h)/2);
}
To copy to clipboard, switch view to plain text mode
and the code for the main window which creates an instance of it is:
(...)
ui->setupUi(this);
myPlot = new plotClass(ui->widget);
(...)
(...)
ui->setupUi(this);
myPlot = new plotClass(ui->widget);
(...)
To copy to clipboard, switch view to plain text mode
, in which widget is the widget I created on the qt designer to be the container of plotclass.
gagagag.PNG
This is basically what I am getting, isn't it possible to tell the qwtplot to fill the whole parent widget?
Thank you!
Bookmarks