PDA

View Full Version : How to obtain the width of a QTableWidget?



Giel Peters
9th January 2006, 22:23
I get stuck with trying to determine the width of a QTableWidget in my application.

In my QTableWidget there are 5 columns. Four of them are of a fixed width and I want to make the third one take all the room that is left in the widget. I have tried to do that on the following way which did not work. So to see what happenend I put in some Line edits to make the values visible.

The sum of the width of all the columns is 477 but the width of the QTableWidget is 100?

Can somebody give me a clue what I've done wrong?


void WachtBoek::makeRemark()
{
QRect tempRect = memoryTableWidget->geometry();
int width = tempRect.width();
int sumWidth = memoryTableWidget->columnWidth( 0 ) + memoryTableWidget->columnWidth( 1 );
sumWidth = sumWidth + memoryTableWidget->columnWidth( 2 ) + memoryTableWidget->columnWidth( 3 );
sumWidth = sumWidth + memoryTableWidget->columnWidth( 4 );

QString widthStr, sumStr;
widthStr = widthStr.setNum( width );
sumStr = sumStr.setNum( sumWidth );
d301LineEdit->setText( widthStr );
d302LineEdit->setText( sumStr );
}


regards,

Giel Peters.

jacek
9th January 2006, 22:32
When do you call that WachtBoek::makeRemark() method? There are some problems with querying the widget size before is it shown for the first time. You might try QTableWidget::sizeHint().

Giel Peters
9th January 2006, 22:43
I call this routine as the last call in the constructor of the application "Wachtboek".

With your suggested "sizeHint()" the value i get returned is 256. A little better as the previous attempt but still not the real width.


regards,
Giel Peters.

Corran
9th January 2006, 23:34
How about http://doc.trolltech.com/4.1/qwidget.html#size-prop that should give the QSize from which you can find the width.