title: How to maintain specific height to width ratio of widget in qt5?
body: <p>I tried overriding methods hasHeightToWidth() and heightToWidth() but it didn't work for some reason.
  Is there some complete example that I can use?</p>
  
  <p><strong>Upd1:</strong></p>
  
  <pre><code>class MyWidget : public QWidget {
      Q_OBJECT
  
  public: 
      MyWidget() {
          QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
          sizePolicy.setHeightForWidth(true);
          setSizePolicy(sizePolicy);
      }
      bool hasHeightForWidth() const override {
          std::cout &lt;&lt; __FUNCTION__ &lt;&lt; std::endl;
          return true;
      }
      int heightForWidth(int w) const override {
          std::cout &lt;&lt; __FUNCTION__ &lt;&lt; " " &lt;&lt; w &lt;&lt; std::endl;
          return w;
      }
      QSize sizeHint() const override {
          return QSize(100, heightForWidth(100));
      }
  };
  </code></pre>
  
  <p>MyWidget instances are inserted in QHBoxLayout.</p>
  
  <p>I use qt5.</p>
  
  <p>Debug std::cout's show that hasHeightForWidth and heightForWidth are called many times</p>