PDA

View Full Version : How do I determine if a QTableWidget's scrollbar is visible?


fuzzywuzzy01
28th August 2007, 00:33
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!

fuzzywuzzy01
29th August 2007, 01:47
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.


bool ExtTable::IsVerticalScrollBarVisible()
{
bool IsVisible = false;

int HeightOfAllRows = 0;
for (int i = 0; i < rowCount(); i++)
HeightOfAllRows += rowHeight(i);

int HeaderHeight = horizontalHeader()->height();
int TableHeight = height();

if ( (HeightOfAllRows + HeaderHeight) > TableHeight )
IsVisible = true;

return IsVisible;
}