You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, January 17th 2012, 2:01am

QTableView background image fixed in lower right corner of viewport

Hi, I've successfully subclassed a QTableView and added an eventFilter that uses QStylePainter to draw a pixmap in the lower right corner of a QTableView that is fixed to the lower right corner of the viewport even when scrolled or resized. Applying this same technique to a QTreeView the pixmap is drawn correctly initially and then gets out of synch with scrolling and resizing.

Code for event filter is below (code tags don't seem to like the python)



def eventFilter(self, obj, ev):

if ev.type() == QEvent.Paint and obj == self.viewport():
h = self.pixmap.rect().height()
w = self.pixmap.rect().width()
r = self.viewport().rect()

x = r.right() - w
if self.verticalScrollBar().isVisible(): x += self.verticalScrollBar().width()
r.setX(x)
r.setWidth(w)

y = r.bottom() - h + self.horizontalScrollBar().height() - 17
if self.horizontalScrollBar().isVisible(): y += self.horizontalScrollBar().height()
r.setY(y)
r.setHeight(h)

QStylePainter(obj).drawItemPixmap(r, Qt.AlignRight, self.pixmap)

return super(TreeView, self).eventFilter(obj, ev)