Results 1 to 4 of 4

Thread: How do I determine if a QTableWidget's scrollbar is visible?

  1. #1
    Join Date
    Aug 2007
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default How do I determine if a QTableWidget's scrollbar is visible?

    How do I determine if my vertical scrollbar is going to be displayed at the time I'm setting up my dialog? In Qt3 MyTable->verticalScrollBar()->isHidden() always worked for me. I've tried isEnabled(), isHidden() and isVisible() but they seem to return the same thing regardless of how many items are in the table. The scroll bar policy is set to as needed. I imagine isVisible would work after the dialog is displayed but that is too late.

    Also does anyone know which of the following lines is the preferable way to determine the scroll bar width? They both seem to work on my dev machine.
    int ScrollBarWidth1 = ui.MyTable->verticalScrollBar()->sizeHint().width();
    int ScrollBarWidth2 = style()->pixelMetric(QStyle::PM_ScrollBarExtent);

    Thanks!
    Last edited by fuzzywuzzy01; 28th August 2007 at 00:45.

  2. #2
    Join Date
    Aug 2007
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: How do I determine if a QTableWidget's scrollbar is visible?

    So I never found a built in way to figure this out. I ended up sub-classing QTableWidget and writing my own query to see if it was visible. Here it is for anyone else who runs into this problem.

    Qt Code:
    1. bool ExtTable::IsVerticalScrollBarVisible()
    2. {
    3. bool IsVisible = false;
    4.  
    5. int HeightOfAllRows = 0;
    6. for (int i = 0; i < rowCount(); i++)
    7. HeightOfAllRows += rowHeight(i);
    8.  
    9. int HeaderHeight = horizontalHeader()->height();
    10. int TableHeight = height();
    11.  
    12. if ( (HeightOfAllRows + HeaderHeight) > TableHeight )
    13. IsVisible = true;
    14.  
    15. return IsVisible;
    16. }
    To copy to clipboard, switch view to plain text mode 

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

    swdev (10th June 2014)

  4. #3
    Join Date
    Jan 2011
    Posts
    18
    Thanks
    6
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How do I determine if a QTableWidget's scrollbar is visible?

    better late than never :

    since view->horizontalHeader() returns a (subclass of) QWidget you can just use isVisible()

  5. #4
    Join Date
    Aug 2008
    Location
    Eastern U.S.
    Posts
    9
    Thanks
    1
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I determine if a QTableWidget's scrollbar is visible?

    Even later, even better!

    I ran into this problem as well, and I hope this will help somebody. I found that if the scroll bar's maximum and minimum values are the same, (usually with the value 0), then the scroll bar will not be visible.

Similar Threads

  1. GraphicsView/GraphicsScene: scrollbar policy Qt::ScrollBarAsNeeded
    By Pieter from Belgium in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2007, 13:15
  2. about scrollbar style
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 13:34
  3. QTableWidget issues
    By Djony in forum Qt Programming
    Replies: 42
    Last Post: 19th December 2006, 23:27
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

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.