[Interest] sizeHint for delegates not wqorking

Frank Rueter | OHUfx frank at ohufx.com
Tue Jul 3 04:11:42 CEST 2018

Hi all,

I am having trouble controlling my table view’s column sizes.
I thought implementing the delegate’s sizeHint was a way to do this but 
it won’t work for me.

Can somebody please point out what I’m missing?
Here is my test code:

|from PySide2 import QtWidgets from PySide2 import QtCore class 
MyItemDelegate(QtWidgets.QStyledItemDelegate): def __init__(self): 
super(MyItemDelegate, self).__init__() def sizeHint(self, option, 
index): # why is this never called? print 'hint' return 
QtCore.QSize(10,10) class MyView(QtWidgets.QTableView): def 
__init__(self, parent=None): super(MyView, self).__init__(parent) 
self.setItemDelegate(MyItemDelegate()) class 
MyModel(QtCore.QAbstractTableModel): def __init__(self, parent=None): 
super(MyModel, self).__init__(parent) self.my_data = [i for i in 
xrange(100)] def data(self, index, role): '''Return required data for 
nodes''' if role == QtCore.Qt.DisplayRole: return 'item 
{}'.format(self.my_data[index.row()]) def columnCount(self, index=None): 
return 2 def rowCount(self, index=None): return len(self.my_data) class 
MyPanel(QtWidgets.QWidget): def __init__(self, parent=None): 
super(MyPanel, self).__init__(parent) self.init_UI() def init_UI(self): 
# widgets self.itemView = MyView() self.model = MyModel() 
self.itemView.setModel(self.model) layout = QtWidgets.QVBoxLayout() 
layout.addWidget(self.itemView) self.setLayout(layout) if __name__ == 
'__main__': import sys app = QtWidgets.QApplication([]) w = MyPanel() 
w.show() sys.exit(app.exec_()) |


ohufxLogo 50x50 <http://www.ohufx.com> 	
	*vfx compositing <http://ohufx.com/compositing.html> | *workflow 
customisation and consulting <http://ohufx.com/customising.html>* *

Your gateway to over 1,000 free tools... right inside of Nuke 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180703/15672446/attachment.html>

More information about the Interest mailing list