I tried overriding methods hasHeightToWidth() and heightToWidth() but it didn't work for some reason. Is there some complete example that I can use?
Upd1:
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 << __FUNCTION__ << std::endl;
        return true;
    }
    int heightForWidth(int w) const override {
        std::cout << __FUNCTION__ << " " << w << std::endl;
        return w;
    }
    QSize sizeHint() const override {
        return QSize(100, heightForWidth(100));
    }
};
MyWidget instances are inserted in QHBoxLayout.
I use qt5.
Debug std::cout's show that hasHeightForWidth and heightForWidth are called many times