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:
Qt Code:
  1. TargetDisplay::TargetDisplay(QWidget *parent)
  2. : QMainWindow(parent)
  3. {
  4. ui.setupUi(this);
  5. d_plot = new RandomPlot(this);
  6.  
  7. QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  8. policy.setHeightForWidth(true);
  9. d_plot->setSizePolicy(policy);
  10.  
  11. ui.horizontalLayout->insertWidget(0, d_plot);
  12. }
To copy to clipboard, switch view to plain text mode 

and then in my RandomPlot widget I have:

Qt Code:
  1. class RandomPlot: public QWidget
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. RandomPlot(QWidget *parent);
  7. ~RandomPlot();
  8.  
  9. int heightForWidth(int w) const {
  10. return w;
  11. }
  12. }
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