开发者

Set QTableWidget cell's borders to 0px

How can I set the cell borders in a QTableWidget to 0px? Preferably I can choose which sides of a cell's border to set to 0, but I can live with set开发者_开发百科ting them all to 0 as well.

EDIT: Either setting the border to 0px or setting the color to white would be good as well.


You can disable all the borders with QTableWidget::setShowGrid, and re-enable some of them with a style sheet (for instance: "QTableView::item { border-left: 1px solid black; }")

The latter are cell interior borders, so they might not be as well aligned as the grid.

If you want to change the borders individually for each cell, you need to write a delegate (like in that answer).


check if QTableWidget's setShowGrid would work for you, smth like this:

tableWidget->setShowGrid(false);

hope this helps, regards


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜