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
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();
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.
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.
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
1 Attachment(s)
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.
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.
Code:
bool TabWidget::hasVisibleScroll()
{
int tabCount = tabBar()->count();
QRect tabBarRect
= tabBar
()->geometry
();
QPoint barTopRight
= tabBarRect.
topRight();
QRect tabRect
= tabBar
()->tabRect
(tabCount
-1);
if( tabRect.topLeft.x() >= barTopRight.x() )
return true;
return false;
}
regards
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.
Re: How to find the presence of scroll bars at run time
Quote:
Originally Posted by
anju123
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