PDA

View Full Version : Minimum QGroupBox size



klnusbaum
16th June 2008, 17:13
I have a QGroupBox that I initially set up with a given title. Through out the program, based on certain user inputs, this QGroupBox gets resized. Sometimes the title of QGroupBox can be slightly long, and sometimes when the QGroupBox is resized to a smaller size the title can get cut off. Can anyone think of a way to set a minimum width on the QGroupBox which would ensure the full title will always be displayed in its entirety?

marcel
16th June 2008, 18:50
After changing the title try a:


QFontMetrics fm(group->font());
int minW = fm.width(group->title());
group->setMinimumWidth(minW);

klnusbaum
17th June 2008, 15:39
Thanks for the suggestion Marcel. It doesn't quite seem to work though. I think I was a little unclear in my stating of the problem though. The title is set when the QGroupBox is constructed. It doesn't changed. The only thing about the QGroupBox that changes is its size. Does that change the problem a little bit?

Here's my attempt to implement the suggested code:


ETGroupBox::ETGroupBox(const QString &title, QWidget *parent):QGroupBox(parent){
setTitle(title);
theGrid = new QGridLayout();
setLayout(theGrid);
QFontMetrics fm(this->font());
int minW = fm.width(this->title());
setMinimumWidth(minW);
}

klnusbaum
19th June 2008, 17:22
I've tried messing around with the QFontMetrics, but I still can't quite seem to get it. In fact, it seems like for some reason, my QGroupBox won't respect any minimum width I set for it. If I call resize(sizeHint()) on it, it doesn't seem to be respecting the minimum width.