Hello,
I have a problem with placing a widget into a horizontalLayout and making it keep an equal aspect ratio (square).
Here is a rough outline of my code:
TargetDisplay
::TargetDisplay(QWidget *parent
){
ui.setupUi(this);
d_plot = new RandomPlot(this);
policy.setHeightForWidth(true);
d_plot->setSizePolicy(policy);
ui.horizontalLayout->insertWidget(0, d_plot);
}
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);
}
To copy to clipboard, switch view to plain text mode
and then in my RandomPlot widget I have:
{
Q_OBJECT
public:
~RandomPlot();
int heightForWidth(int w) const {
return w;
}
}
class RandomPlot: public QWidget
{
Q_OBJECT
public:
RandomPlot(QWidget *parent);
~RandomPlot();
int heightForWidth(int w) const {
return w;
}
}
To copy to clipboard, switch view to plain text mode
but my widget is not maintaining an equal aspect ratio. Can somebody please tell me what I'm doing wrong? Thank you!
-James
Bookmarks