QT8seven
7th December 2011, 02:46
#include "calcbutton.h"
QSize calcButton::sizeHint()
{
return QSize(35,25);
}
calcButton::calcButton(QString str) : QPushButton(str)
{
setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Mi nimum);
setMinimumSize(35,25);
setMaximumSize(1000,1000);
}
Despite the obvious lacking header file, this code is complete. The header is as can be expected, it simply inherits QPushButton in order to modify the sizing. This is done in an attempt to test out sizing, however, I have come to a problem:
Using the above code, and many other alternatives I've tried, I have been unable to understand why when placing a lot of "calcButtons" within a QGridLayout the buttons all want to be larger than they need to be. They are created with minimal height, but the width is almost double the size-hint. I have a feeling it has to do with the widget which is holding everything. Basically I do the following:
Create new widget.
Create grid layout.
Add a bunch of calcButtons.
Set as central widget.
setLayout
The only way I have been successful with getting the buttons to be minimal size is by using setMaximumSize on the parent widget/central widget, which obviously isn't correct.
QSize calcButton::sizeHint()
{
return QSize(35,25);
}
calcButton::calcButton(QString str) : QPushButton(str)
{
setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Mi nimum);
setMinimumSize(35,25);
setMaximumSize(1000,1000);
}
Despite the obvious lacking header file, this code is complete. The header is as can be expected, it simply inherits QPushButton in order to modify the sizing. This is done in an attempt to test out sizing, however, I have come to a problem:
Using the above code, and many other alternatives I've tried, I have been unable to understand why when placing a lot of "calcButtons" within a QGridLayout the buttons all want to be larger than they need to be. They are created with minimal height, but the width is almost double the size-hint. I have a feeling it has to do with the widget which is holding everything. Basically I do the following:
Create new widget.
Create grid layout.
Add a bunch of calcButtons.
Set as central widget.
setLayout
The only way I have been successful with getting the buttons to be minimal size is by using setMaximumSize on the parent widget/central widget, which obviously isn't correct.