Подскажите как убрать выделение для любой ячейки в таблице?
Для ячеек с QTableWidgetItem можно установить
.setFlags(Qt.ItemIsDragEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsSelectable)
для таблицы можно установить
table.setSelectionMode(QAbstractItemView.NoSelection)
table.setEditTriggers(QAbstractItemView.NoEditTriggers)
Но всё равно остаётся эта рамка при нажатии на ячейку
Прилагаю минимальный пример:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLineEdit, \
QLabel,QMainWindow, QMenu, QDesktopWidget, QHBoxLayout, \
QGridLayout, QVBoxLayout, QTableWidget, QTableWidgetItem, QLayout, \
QFormLayout, QFrame, QAbstractItemView
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtCore import QSize, Qt, QModelIndex
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(800, 400, 300, 300)
self.setWindowTitle('test')
centralwidget = QWidget(self)
layout = QGridLayout(self)
centralwidget.setLayout(layout)
search_table_box = QVBoxLayout()
table = QTableWidget(5, 5)
table.setShowGrid(False)
table.setSelectionMode(QAbstractItemView.NoSelection)
table.setEditTriggers(QAbstractItemView.NoEditTriggers)
table.setCurrentIndex(QModelIndex())
table.setHorizontalHeaderLabels(['1',"2","3","4","5"])
for row in range(table.rowCount()):
gbox = QGridLayout()
framebox = QFrame()
framebox.setLayout(gbox)
table.setCellWidget(row, 2, framebox)
hbox8 = QHBoxLayout()
framebox2 = QFrame()
framebox2.setLayout(hbox8)
table.setCellWidget(row, 3, framebox2)
hbox9 = QHBoxLayout()
framebox3 = QFrame()
framebox3.setLayout(hbox9)
table.setCellWidget(row, 0, framebox3)
required_la_box = QHBoxLayout()
framebox4 = QFrame()
framebox4.setLayout(required_la_box)
table.setCellWidget(row, 4, framebox4)
fe = QLabel()
column1_pb = QPushButton("hello")
hbox9.addWidget(column1_pb)
widget = QTableWidgetItem("hello2")
table.setItem(row % 60, 1, widget)
widget.setFlags(Qt.ItemIsDragEnabled
| Qt.ItemIsUserCheckable | Qt.ItemIsSelectable)
layout.addWidget(table)
self.setCentralWidget(centralwidget)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())