我試圖創建一個委託在圖標模式下將自定義小部件繪製爲列表視圖中的元素。我有或多或少的工作,但我不能讓小部件繪製在正確的地方,似乎他們正在考慮(0,0)主窗口的原點而不是列表視圖的來源。我需要通過什麼來在正確的位置呈現小部件?我知道我可以通過一個偏移量...我如何計算主窗口和列表視圖之間的偏移量?qwidget.render在QStyledItemDelegate中繪製偏移量
這是我委託我的繪製方法(從QStyledItemDelegate派生)
def paint(self, painter, option, index):
painter.save()
if option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight());
model = index.model()
myWidget = model.listdata[index.row()]
myWidget.setGeometry(option.rect)
myWidget.render(painter, option.rect.topLeft())
painter.restore()
感謝
/J