pyqt - 在pyqt中隐藏qtablewidget中选定单元格的边框?

标签 pyqt qtablewidget

有没有办法我可以在 qtablewidget 中隐藏所选单元格的边框(或使边框颜色为白色)。默认情况下,会显示带虚线的边框。你能帮帮我吗...

最佳答案

Qt::NoFocus将删除 QTableWidget 中行的选定状态.Python3/PySide2接受答案的版本:

class NoFocusDelegate(QtWidgets.QStyledItemDelegate):
    def paint(self, painter: PySide2.QtGui.QPainter, option: PySide2.QtWidgets.QStyleOptionViewItem, index: PySide2.QtCore.QModelIndex) -> None:
        itemOption = QtWidgets.QStyleOptionViewItem(option)
        if option.state & QtWidgets.QStyle.State_HasFocus:
            itemOption.state = itemOption.state ^ QtWidgets.QStyle.State_HasFocus
        super().paint(painter, itemOption, index)

table.setItemDelegate(NoFocusDelegate())
非常适合我。

关于pyqt - 在pyqt中隐藏qtablewidget中选定单元格的边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2055705/

相关文章:

python - QtSql 连接多个数据库

python - 如何创建正确跨越多个页面的可打印列表

qt - 如何更改 QTableWidget 中空白单元格的背景颜色

Python:QTableWidget 中的数值排序

c++ - 如何将具有特定颜色的文本添加到 qtablewidget 中的垂直标题项?

c++ - 在 QTableWidget 中区分交替行颜色和选择颜色

python - 从 unicode 字符串发送击键 pyqt pyside

python - 在 Qt5 日历小部件中突出显示日期间隔

c++ - QStyledItemDelegate:区分 closeEditor() 或 setModelData() 的原因

python - PyQt5:Gtk-CRITICAL **:IA__gtk_widget_style_get:断言 'GTK_IS_WIDGET (widget)' 失败