PDA

View Full Version : QAbstractScrollArea scrollbar positions



ugluk
12th September 2011, 16:00
I have a QTreeView subclass in which I would like to obtain positions of it's scrollbars (if any). So I do:



qDebug() <<
horizontalScrollBar()->mapToParent(horizontalScrollBar()->pos()) <<
verticalScrollBar()->mapToParent(verticalScrollBar()->pos());


The result is always (0,0), with or without the map at runtime. Please help.

wysota
12th September 2011, 16:05
pos() is already in the parent's coordinate space. It's equivalent to:

horizontalScrollBar()->mapToParent(QPoint(0,0));

ugluk
12th September 2011, 16:13
Thanks, but even without the map, as I wrote, the result is QPoint(0, 0). Are the QAbstractView's scrollbars part of the viewport, or are they outside of them? Basically, for testing purposes I'd like to do:



QPainter painter(this);
painter.fillRect(rect(), Qt::yellow);


Of course, this doesn't work because of the QAbstractScrollArea. So how could I erase the background of QAbstractViewItem manually?

EDIT:
Would it be possible to filter paint events of the viewport() or the both *ScrollBar()s and do some painting before forwarding the event?

wysota
12th September 2011, 16:30
What is it exactly that you want to do?

ugluk
12th September 2011, 16:36
By default, QAbstractItemView derivatives all erase their backgrounds at every repaint event. But what, if the view is custom and the view's items themselves erase their backgrounds? The view's erase is then superfluous. But if I do:



setAttribute(Qt::WA_NoSystemBackground);


on the view, the backgrounds of the view's scrollbars will not erase. Therefore, I wanted to erase their backgrounds "manually" (via fillRect()), while leaving the view's items to erase their own backgrounds.

wysota
13th September 2011, 09:44
By default, QAbstractItemView derivatives all erase their backgrounds at every repaint event. But what, if the view is custom and the view's items themselves erase their backgrounds?
What if there are not enough items to cover all the view or some items have transparent background?


The view's erase is then superfluous. But if I do:



setAttribute(Qt::WA_NoSystemBackground);


on the view, the backgrounds of the view's scrollbars will not erase. Therefore, I wanted to erase their backgrounds "manually" (via fillRect()), while leaving the view's items to erase their own backgrounds.
Then set the attribute on the view's viewport and not on the view itself. However I don't think this optimalization is worth the effort you are putting into it.