Results 1 to 3 of 3

Thread: How to get the QTableWidget Scrollbar Thickness?

  1. #1
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    18

    Question How to get the QTableWidget Scrollbar Thickness?

    Hi,

    I am trying to get a column to expand when the dialog resizes. Currently the table and column resizes. But I was wondering if there is a better way to do it. I don't want to have to use the horizontal scrollbar.

    At the moment I don't know a way to collect the scrollbar thickness. I just use 19. I believe I need to use something like: QStyle::PM_ScrollBarExtent

    Qt Code:
    1. #define PHONEBOOK_DATA_COL 3
    2.  
    3. #define PHONEBOOK_INDEX_WIDTH 55
    4. #define PHONEBOOK_NORMAL_HOURS_WIDTH 85
    5. #define PHONEBOOK_AFTER_HOURS_WIDTH 85
    6.  
    7. void PhoneBook::resizeEvent(QResizeEvent *)
    8. {
    9. int colwidth = m_ui->tableWidget->width() - (PHONEBOOK_INDEX_WIDTH
    10. + PHONEBOOK_NORMAL_HOURS_WIDTH
    11. + PHONEBOOK_AFTER_HOURS_WIDTH
    12. + 19);
    13.  
    14. m_ui->tableWidget->setColumnWidth(PHONEBOOK_DATA_COL, colwidth);
    15. }
    To copy to clipboard, switch view to plain text mode 

    Thanks
    Brendan

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to get the QTableWidget Scrollbar Thickness?

    I did something similar for a QTableView by grabbing the geometry of the actual scroll bar:
    Qt Code:
    1. QRect g = m_ui->tableViewRight->horizontalScrollBar()->geometry();
    To copy to clipboard, switch view to plain text mode 
    Then use QRect::height() or QRect::width().
    It would be interesting to hear of a way to get the equivalent from the style system.

    As for your desire to have one column soak up all the excess space by growing, you should look at QHeaderView::setResizeMode() and set a resize mode of QHeaderView::Stretch on that column.

  3. The following user says thank you to ChrisW67 for this useful post:

    grantbj74 (10th August 2009)

  4. #3
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    18

    Default Re: How to get the QTableWidget Scrollbar Thickness?

    Thanks! Yes thats a better way to do it.

    Heres the code:

    Qt Code:
    1. QHeaderView *header = m_ui->tableWidget->horizontalHeader();
    2.  
    3. header->setResizeMode( PHONEBOOK_DATA_COL, QHeaderView::Stretch);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Treeview scrollbar not updating when inserting rows
    By Khal Drogo in forum Qt Programming
    Replies: 11
    Last Post: 29th November 2007, 13:13
  2. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  3. GraphicsView/GraphicsScene: scrollbar policy Qt::ScrollBarAsNeeded
    By Pieter from Belgium in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2007, 13:15
  4. about scrollbar style
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 13:34
  5. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46

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
  •  
Qt is a trademark of The Qt Company.