在pyqt中隐藏qtablewidget中所选单元格的边框? [英] Hide the border of the selected cell in qtablewidget in pyqt?
问题描述
有没有办法在qtablewidget中隐藏所选单元格的边框(或将边框颜色设为白色)..默认情况下显示虚线边框..你能帮我... >
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...
推荐答案
您试图隐藏的选定单元格周围的虚线边框看起来像是一个焦点矩形.任何给定的单元格都可以具有焦点并且不会同时被选中,反之亦然.如果您希望此边框不被绘制,请使用项目委托.在那里您可以在绘制之前从项目的状态中删除 State_HasFocus 样式.请参阅下面的示例,了解如何执行此操作,它是 C++,如果您在将其转换为 python 时遇到问题,请告诉我
It looks like this dotted border around selected cell you're trying to hide is a focus rectangle. Any given cell can have focus and not be selected at the same time and vice-versa. If you want this border to not get painted use an item delegate. There you can remove State_HasFocus style from the item's state before painting it. Pls, see an example below on how to do this, it's c++, let me know if you have troubles converting it to python
// custom item delegate class
class NoFocusDelegate : public QStyledItemDelegate
{
protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
};
void NoFocusDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const
{
QStyleOptionViewItem itemOption(option);
if (itemOption.state & QStyle::State_HasFocus)
itemOption.state = itemOption.state ^ QStyle::State_HasFocus;
QStyledItemDelegate::paint(painter, itemOption, index);
}
...
// set the item delegate to your table widget
ui->tableView->setItemDelegate(new NoFocusDelegate());
希望对您有所帮助,问候
hope this helps, regards
这篇关于在pyqt中隐藏qtablewidget中所选单元格的边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!