PDA

View Full Version : Maintaining square widget (plot)



jmsbc
28th May 2009, 23:44
Hi,

Is there a way to maintain QwtPlot's physical aspect ratio in a layout? Uwe, you suggested QwtPlotRescaler before, but now I need QwtPlot to look like a square widget instead of rectangle when the window stretches. Here's what I tried to do:



TargetDisplay::TargetDisplay(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
d_plot = new RandomPlot(this);

QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Preferred);
policy.setHeightForWidth(true);
d_plot->setSizePolicy(policy);

ui.horizontalLayout->insertWidget(0, d_plot);
}


and then in my RandomPlot widget I have:



class RandomPlot: public IncrementalPlot
{
Q_OBJECT

public:
RandomPlot(QWidget *parent);
~RandomPlot();

int heightForWidth(int w) const {
return w;
}
}


But it's not remaining a square whenever the window stretches. What else do I need to include? Thank you.

-James

jmsbc
29th May 2009, 01:18
Nevermind, I figured it out. Instead of adding d_plot directly to the horizontalLayout, I added it to QwtDynGridLayout first, and then added the layout to the horizontalLayout:



gLayout = new QwtDynGridLayout(this);
gLayout->addWidget(d_plot);
ui.horizontalLayout->insertLayout(0, gLayout);


Now I get a square