Results 1 to 9 of 9

Thread: How to find the presence of scroll bars at run time

  1. #1
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How to find the presence of scroll bars at run time

    I have a problem where I am changing the image depending on the area I have on the screen.
    This area is calculated depending on the Tab widget width. Depending on the text,the tab widget adds a scroll bar.
    Now I have to decide on the image based on the tab widget width . Is there a way to find out the width. By default the tab widget width is set to the desktop width

  2. #2
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to find the presence of scroll bars at run time

    to get presence of scroll bars at run time
    use this:
    verticalScrollBar()->isVisible();
    or
    horizontalScrollBar()->isVisible();


  3. #3
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find the presence of scroll bars at run time

    Rajesh,
    these calls are the member function of QScrollView or QAbstractScrollArea.
    I am using QTabWidget class.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to find the presence of scroll bars at run time

    I presume you use QTextEdit for showing the text. QTextEdit is a QAbstractScrollArea.
    J-P Nurmi

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find the presence of scroll bars at run time

    But a tab widget does not automatically adds scroll bars.
    You must add them manually.

    The only scroll it adds automatically is the scroll for the tab bar widgets.

    Could you provide a screenshot?
    Or at least make sure of who's adding the scroll bars...
    Could it be one of the widgets in the tab widget?

    Regards

  6. #6
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find the presence of scroll bars at run time

    May be I had framed the query incorrectly. The scroll bar is added automatically by the tab bar widgets, property (use scrollbuttons)
    I have also added the screenshot.
    Attached Images Attached Images

  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find the presence of scroll bars at run time

    Oh, in this case you need a hack. You have to subclass the tab widget in order to have access to its QTabBar.
    Qt Code:
    1. bool TabWidget::hasVisibleScroll()
    2. {
    3. int tabCount = tabBar()->count();
    4. QRect tabBarRect = tabBar()->geometry();
    5. QPoint barTopRight = tabBarRect.topRight();
    6.  
    7. QRect tabRect = tabBar()->tabRect(tabCount-1);
    8. if( tabRect.topLeft.x() >= barTopRight.x() )
    9. return true;
    10. return false;
    11. }
    To copy to clipboard, switch view to plain text mode 

    regards

  8. #8
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find the presence of scroll bars at run time

    thanks marcel for the code..
    just one thing the line if( tabRect.topLeft.x() >= barTopRight.x(i) ), is giving me the "true" status in both the cases.
    In my case the TabWidget is given a resize event during the initialisation of the screen , but the above code always gives the default size, so I have modified the code to the code given below:
    if(tabRect.topLeft().x() >= QApplication::desktop()->width() )
    The tabbar is resized to desktop's width in the starting.

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find the presence of scroll bars at run time

    Quote Originally Posted by anju123 View Post
    thanks marcel for the code..
    just one thing the line if( tabRect.topLeft.x() >= barTopRight.x(i) ), is giving me the "true" status in both the cases.
    In my case the TabWidget is given a resize event during the initialisation of the screen , but the above code always gives the default size, so I have modified the code to the code given below:
    if(tabRect.topLeft().x() >= QApplication::desktop()->width() )
    The tabbar is resized to desktop's width in the starting.
    Well, OK then. I didn't know in exactly what moment you needed it.
    I thought you wanted to know if scrollbars are present somewhere during runtime, after initialization.

    Regards

Similar Threads

  1. QScrollArea's Scroll Bars
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2006, 13:27

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.