Maybe there are better ways but this is how i did it
1. subclass QPushButton.
2. overwrite the virtual sizeHint() function
3. In this function return the prefered sizeHint (QPushButton sizeHint().width=80)
4. call adjustSize() on your subclassed QPushButton.
Header
class QModifiedQPushButton : public QPushButton
{
Q_OBJECT
public:
QModifiedQPushButton(const QString &text ,QWidget * parent = 0, const char * name = 0 );
virtual ~QModifiedQPushButton();
QSize sizeHint() const;
};
CPP
QModifiedQPushButton::QModifiedQPushButton(const QString &text ,QWidget * parent,const char * name) : QPushButton(text,parent,name)
{
}
QModifiedQPushButton::~QModifiedQPushButton()
{
}
QSize QModifiedQPushButton::sizeHint() const
{
return QSize(40,28); // you can return whatever size here
}
0 תגובות:
Post a Comment