Results 1 to 4 of 4

Thread: How to obtain the width of a QTableWidget?

  1. #1
    Join Date
    Jan 2006
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How to obtain the width of a QTableWidget?

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to obtain the width of a QTableWidget?

    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().

  3. #3
    Join Date
    Jan 2006
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to obtain the width of a QTableWidget?

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    England
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to obtain the width of a QTableWidget?

    How about http://doc.trolltech.com/4.1/qwidget.html#size-prop that should give the QSize from which you can find the width.

Similar Threads

  1. QTableWidget column width and resizing
    By shooogun in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2008, 22:31
  2. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  3. width of a QTableWidget
    By magland in forum Newbie
    Replies: 4
    Last Post: 14th June 2007, 13:09
  4. changing column width of QTableWidget
    By juliarg in forum Newbie
    Replies: 4
    Last Post: 22nd March 2007, 15:51
  5. Replies: 6
    Last Post: 13th October 2006, 14:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.