Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide the border of the selected cell in qtablewidget in pyqt?

Is there a way i can hide the border of the selected cell(or make the border color as white)in a qtablewidget.. By default a border with dotted line is shown.. Can u help me...

like image 225
Jeba Avatar asked Jan 13 '10 09:01

Jeba


2 Answers

Qt::NoFocus will remove the selected state of rows in QTableWidget.

The Python3/PySide2 version to the accepted answer:

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())

Worked perfectly for me.

like image 107
BaiJiFeiLong Avatar answered Sep 26 '22 16:09

BaiJiFeiLong


I prefer to do:

ui->tableWidget->setFocusPolicy(Qt::NoFocus);

You can also change the focus policy using the design tab.

like image 28
Toge Avatar answered Sep 22 '22 16:09

Toge