PDA

View Full Version : How to get the QTableWidget Scrollbar Thickness?



grantbj74
5th August 2009, 07:57
Hi,

I am trying to get a column to expand when the dialog resizes. Currently the table and column resizes. But I was wondering if there is a better way to do it. I don't want to have to use the horizontal scrollbar.

At the moment I don't know a way to collect the scrollbar thickness. I just use 19. I believe I need to use something like: QStyle::PM_ScrollBarExtent



#define PHONEBOOK_DATA_COL 3

#define PHONEBOOK_INDEX_WIDTH 55
#define PHONEBOOK_NORMAL_HOURS_WIDTH 85
#define PHONEBOOK_AFTER_HOURS_WIDTH 85

void PhoneBook::resizeEvent(QResizeEvent *)
{
int colwidth = m_ui->tableWidget->width() - (PHONEBOOK_INDEX_WIDTH
+ PHONEBOOK_NORMAL_HOURS_WIDTH
+ PHONEBOOK_AFTER_HOURS_WIDTH
+ 19);

m_ui->tableWidget->setColumnWidth(PHONEBOOK_DATA_COL, colwidth);
}


Thanks
Brendan

ChrisW67
7th August 2009, 05:31
I did something similar for a QTableView by grabbing the geometry of the actual scroll bar:

QRect g = m_ui->tableViewRight->horizontalScrollBar()->geometry();
Then use QRect::height() or QRect::width().
It would be interesting to hear of a way to get the equivalent from the style system.

As for your desire to have one column soak up all the excess space by growing, you should look at QHeaderView::setResizeMode() and set a resize mode of QHeaderView::Stretch on that column.

grantbj74
10th August 2009, 03:37
Thanks! Yes thats a better way to do it.

Heres the code:



QHeaderView *header = m_ui->tableWidget->horizontalHeader();

header->setResizeMode( PHONEBOOK_DATA_COL, QHeaderView::Stretch);