i have reimplemented(overloaded) a sizeHint()
function in a customized QPushButton
class like this:
QSize CustQPushButton::sizeHint()const
{
QWidget *parentWindow=this->parentWidget(); //a pointer to the parent window
return QSize(parentWindow->width()/10,60);
}
the problem is :
When the window is initially displayed the width of my buttons are as expected(1/10 the window), but when the window is resized the
buttons are not resized proportionally to the window(the parent). The CustQPushButton
Size Policy is set to Fixed/Fixed
and my instantiated buttons are inside a QGridLayout.
Can someone please help me?
You don't need custom classes for such a trivial thing. Purpose of size hint is entirely different. Default layouts can handle 1/10 width. You should use QGridLayout::setColumnStretch
function. For example, setting stretch factors of two columns to 1 and 9 will resize 1st column to 1/10 of parent (assuming content of the 2nd column can grow enough).