PDA

View Full Version : How to find the presence of scroll bars at run time



anju123
24th July 2007, 11:56
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

rajesh
24th July 2007, 12:06
to get presence of scroll bars at run time
use this:
verticalScrollBar()->isVisible();
or
horizontalScrollBar()->isVisible();

anju123
25th July 2007, 13:25
Rajesh,
these calls are the member function of QScrollView or QAbstractScrollArea.
I am using QTabWidget class.

jpn
25th July 2007, 13:27
I presume you use QTextEdit for showing the text. QTextEdit is a QAbstractScrollArea.

marcel
25th July 2007, 13:31
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

anju123
26th July 2007, 10:20
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.

marcel
26th July 2007, 10:33
Oh, in this case you need a hack. You have to subclass the tab widget in order to have access to its QTabBar.


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

anju123
28th July 2007, 20:28
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.

marcel
28th July 2007, 20:30
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