[Interest] QTreeView width with scroll bar
Tony Rietwyk
tony at rightsoft.com.au
Thu Nov 8 11:07:50 CET 2012
> Sent: Thursday, 8 November 2012 6:40 PM
>
> On 2012/11/08 09:23 AM, Alex Strickland wrote:
>
> > However, when the QTreeView gets long enough to automatically add a
> > scroll bar - my calculations don't work and one of the check box
> > columns is obscured by the scrollbar. How can I check if the scroll
> > bar is activated and, if so, obtain it's width to factor into my
calculation?
>
> I should write the message and just not send it... :
>
> class CrossTabTreeView : public QTreeView {
> public:
> CrossTabTreeView(QWidget* parent = 0) : QTreeView(parent) {}
> void resizeEvent(QResizeEvent* /*event - suppress unused warning*/)
> {
> if (model()->columnCount() == CrossTabView::ColumnCount) {
> int scrollBarWidth = 0;
> QScrollBar* scrollBar = verticalScrollBar();
> if (scrollBar) {
> if (scrollBar->isVisible())
> scrollBarWidth = scrollBar->width();
> }
> resizeColumnToContents(CrossTabView::RowColumn);
> resizeColumnToContents(CrossTabView::ColumnColumn);
> setColumnWidth(CrossTabView::QuestionColumn,
> width() - columnWidth(CrossTabView::RowColumn)
> - columnWidth(CrossTabView::ColumnColumn) -
> scrollBarWidth);
> }
> }
> };
>
> --
> Regards
> Alex
Hi Alex,
The QAbstractScrollArea docs are a bit vague. Many of the standard event
handlers are overloaded to be called when the viewport (sub) widget gets the
events. The docs don't say what happens to the normal events for
QAbstractScrollArea. When a resize occurs, does resizeEvent only get called
once for the viewport, or twice? If twice, how do we know which widget the
event is for?
Instead of width() - scrollBarWidth, I suggest to use viewport()->width(),
which should already exclude the vertical scroll bar.
Tony.
More information about the Interest
mailing list