Hi All ,
I've been tring to fit a QPushbutton according to it's text , but was unable to do so.
Can anyone assist?
Hi All ,
I've been tring to fit a QPushbutton according to it's text , but was unable to do so.
Can anyone assist?
use adjustSize().
Give me some credit i've already tried this , but it was not successfull.
Let me explain abit , I'm using this pushbutton as awidget in Qtable.
Here's the code (I've left some parts):
Qt Code:
reset = new QModifiedQPushButton("reset",m_table); reset->setEnabled(false); set = new QModifiedQPushButton("set",m_table); connect(set,SIGNAL(clicked()),reset,SLOT(setEnable())); m_table->setCellWidget(m_table->numRows()-1,5,set); m_table->setCellWidget(m_table->numRows()-1,6,reset); set->adjustSize(); reset->adjustSize(); for(int i = 0 ; i< m_table->numCols();i++) m_table->adjustColumn(i);To copy to clipboard, switch view to plain text mode
manged to Fix the problem!!
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.
Code:
Qt Code:
Header -> { Q_OBJECT public: virtual ~QModifiedQPushButton(); }; CPP -> QModifiedQPushButton::QModifiedQPushButton(const QString &text ,QWidget * parent,const char * name) : QPushButton(text,parent,name) { } QModifiedQPushButton::~QModifiedQPushButton() { } { }To copy to clipboard, switch view to plain text mode
Why not just call setFixedSize?
Qt Code:
mypushbutton->setFixedSize(40,25);To copy to clipboard, switch view to plain text mode
BTW. You don't need the Q_OBJECT macro in the class you have shown here.
Bookmarks