小编Den*_*sen的帖子

QTreeView数据改变了信号/槽实现?

我正在使用 pyqt5 / python 3.7 / win10,并且我有一个 QTreeView,它只有一个可编辑列,可以很好地编辑。我现在需要做的是告诉程序该字段已更改(或检查是否已更改),无论是按下回车键还是输入键,或者由于鼠标单击其他任何地方而导致该字段失去焦点。

我已经包含了一个简单的程序,它反映了迄今为止我的全部情况及其所有图层,并且我们选择单击而不是双击来选择要编辑的字段。

我花了相当多的时间试图解决这个问题,虽然我已经看到了可能的答案,但我还没有找到适合我的答案。我确信这可能相当简单,但我在实施该解决方案时花了很长时间。

from sys import exit as sysExit

from PyQt5.QtCore import *
from PyQt5.QtGui  import *
from PyQt5.QtWidgets import *

class CustomItemModel(QStandardItemModel):
    def headerData(self, section, orientation, role):
        if role == Qt.ForegroundRole:
            brush = QBrush()
            brush.setColor(Qt.blue)
            brush.setStyle(Qt.SolidPattern)
            return brush

        elif role == Qt.BackgroundRole:
            brush = QBrush()
            brush.setColor(Qt.yellow)
            brush.setStyle(Qt.SolidPattern)
            return brush

        elif role == Qt.FontRole:
            font = QFont()
            font.setBold(True)
            font.setPointSize(10)
            return font

        return super().headerData(section, orientation, role)

class ItemDsplyr(QTreeView):
    def __init__(self, CentrPane):
        QTreeView.__init__(self, CentrPane)
        self.CntrPane …
Run Code Online (Sandbox Code Playgroud)

python pyqt qtreeview pyqt5 python-3.7

3
推荐指数
1
解决办法
1630
查看次数

标签 统计

pyqt ×1

pyqt5 ×1

python ×1

python-3.7 ×1

qtreeview ×1