I'm wondering if anyone knows of, perhaps a flag to disable the gray dotted border that appears when you single click on a QTableWidget's cell.
Thanks.
C++: tableWidget->setFocusPolicy(Qt::NoFocus);
Python: tableWidget.setFocusPolicy(QtCore.Qt.NoFocus)
Be aware that you will lose the ability to process keyboard events, but mouse events will work fine.
It seems like you want to remove the border when the cell gets the focus.
Try editing the Stylesheet as follows.
QTableWidget {
outline: 0;
}
This worked for me perfectly.
The easiest way to do it for me without affecting widget's focus policy and using qss is to create the following custom delegate and install it for table:
*.h:
class FocusControlDelegate : public QStyledItemDelegate {
public:
FocusControlDelegate(QObject *parent = 0);
virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const;
void setFocusBorderEnabled(bool enabled);
protected:
bool f_focus_border_enabled;
};
*.cpp:
FocusControlDelegate::FocusControlDelegate(QObject *parent) : QStyledItemDelegate(parent) {
f_focus_border_enabled = false;
}
void FocusControlDelegate::setFocusBorderEnabled(bool enabled) {
f_focus_border_enabled = enabled;
}
void FocusControlDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const {
QStyledItemDelegate::initStyleOption(option, index);
if(!f_focus_border_enabled && option->state & QStyle::State_HasFocus)
option->state = option->state & ~QStyle::State_HasFocus;
}
That gray dotted border indicates that that widget has focus.
Setting the below at the widget level should do the trick.
setFocusPolicy( Qt::NoFocus )
qApp->setStyleSheet ( " QTableWidget::item:focus { border: 0px }" );