[PyQt] HeaderToolTip and Coredump

Jeroen Andreß jeroen.andress at onlinehome.de
Mon May 18 18:56:28 BST 2009


hi,

i am working with python qt 3.3. And I want a tooltip on a table header.
Here is my code:

#!/usr/bin/python
# -.- coding: utf-8 -.-

import sys
from qt import *
from qttable import *

class HeaderToolTip(QToolTip):
	def __init__(self, header, group=None):
		QToolTip.__init__(self, header, group)
		

	def maybeTip(self, p):
		header = QToolTip.parentWidget(self)
		section = 0
		print header.orientation()
	        if header.orientation() == Qt.Horizontal:
	            section = header.sectionAt( header.offset() + p.x() )
	        else:
         	    section = header.sectionAt( header.offset() + p.y() )

	        tipString = header.label( section )
	        QToolTip.tip( self, header.sectionRect( section ), tipString )



class MainWidget(QWidget):
	def __init__(self, parent=None):
		QWidget.__init__(self, parent)
		print self
		self.layout = QHBoxLayout(self, 5,5,"layout")
		
		table = QTable(2,2,self, "table")


		HeaderToolTip(table.horizontalHeader())

		t = HeaderToolTip(table.horizontalHeader())


		self.layout.addWidget( table )


	
if __name__=="__main__":
	a = QApplication(sys.argv)		
	w = MainWidget(None)
	table = QTable(5,5,w,"table2")
	w.layout.addWidget(table)
	print w
	t = HeaderToolTip(table.horizontalHeader())
	a.setMainWidget(w)
	w.show()
	a.exec_loop()


The rigth table works, but the left exits with core dump.

jeroen


More information about the PyQt mailing list