问题
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.
回答1:
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.
回答2:
It seems like you want to remove the border when the cell get the focus.
Try editing the Stylesheet as follows.
QTableWidget {
outline: 0;
}
This worked for me perfectly.
回答3:
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;
}
回答4:
qApp->setStyleSheet ( " QTableWidget::item:focus { border: 0px }" );
回答5:
That gray dotted border indicates that that widget has focus.
Setting the below at the widget level should do the trick.
setFocusPolicy( Qt::NoFocus )
回答6:
QPushButton { outline: none; }
来源:https://stackoverflow.com/questions/9044570/qt-qtablewidgets-gray-dotted-border-around-a-selected-cell