私がしばらくの間戦ってきたこの厄介な問題を誰かが助けてくれることを願っています. デリゲート列のテーブルビューにボタンを挿入するために添付されたコードで管理しました。
問題は、ボタンを押すには、含まれているセルをダブルクリックして「アクティブ化」する必要があることです。セルがアクティブになると、ボタンを押すことができるので、合計で 3 回クリックして押す必要があります。これは、平均的なユーザーにとって混乱を招く可能性があります。
この問題を pyqt メーリング リストに投稿したところ、次のような回答が得られました。
「何が起こるかというと、TableWidget がクリックを受け取るとエディターが作成されますが、エディターはまだクリックを受け取っていません。ほとんどの場合、これで完璧ですが、ボタンを描画する場合はそうではありません。」
誰かここに来たことがありますか?
前もって感謝します、クリス
class AnimLinkButtons(QtGui.QStyledItemDelegate):
mouse_isPressed = False
def __init__(self, parent = None):
QtGui.QStyledItemDelegate.__init__(self, parent)
def createEditor(self, parent, option, index):
column = index.column()
button = QtGui.QPushButton(parent)
button.setText(self.text(index))
ButtonLoc = self.ButtonLocation(option)
button.setGeometry(ButtonLoc)
Cellvalue = index.model().data(index, QtCore.Qt.EditRole)
row = index.row()
AssetId = index.model().data(index.model().index(row, 0)).toString()
AnimTurntablePath = shotsGetData.getAssetTurntablePath(AssetId)
browsePath = shotsGetData.getAssetPath(AssetId)
#toAvidComp = shotsGetData.gettoAvidComp(ShotId)
# Connect to button
button.clicked.connect(lambda: self.mousePressEvent(index, browsePath, AssetTurntablePath))
return button
def setEditorData(self, editor, index):
button = editor
if not button:
return
def setModelData(self, editor, model, index):
button = editor
if not button:
return
def updateEditorGeometry(self, editor, option, index):
ButtonLoc = self.ButtonLocation(option)
editor.setGeometry(ButtonLoc)
def paint(self, painter, option, index):
opt = QtGui.QStyleOptionButton()
#opt.icon = self.icon()
opt.text = self.text(index)
opt.rect = option.rect
opt.palette = option.palette
opt.rect = self.ButtonLocation(opt)
QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, painter)
def ButtonLocation(self, option):
r = option.rect
x = r.left() + 10
y = r.top() + 10
w = 30;
h = 30
return QRect(x,y,w,h);
def text(self, index):
#print self.column
column = index.column()
if column == 7:
return QtCore.QString("Mov")
def mousePressEvent(self, index, browsePath , AssetTurntablePath):
column = index.column()
print "PRESSSED"
if column == 7:
subprocess.Popen(AnimTurntablePath, shell=True)