开发者

How to highlight a row in a QTableWidget with a rounded rectangle?

开发者 https://www.devze.com 2022-12-07 17:54 出处:网络
I am using Pyside2 for python GUI. I am currently working on a QTableWidget. This QTableWidget has 3 columns and 10 rows.

I am using Pyside2 for python GUI. I am currently working on a QTableWidget. This QTableWidget has 3 columns and 10 rows.

First, when I click on any item in the QTableWidget, I want the entire row to be selected. So I set the selection behaviour using

self.ui.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)

Next, I want the entire row to be highlighted in a rounded rectangle shape, so I set the qt style sheet:

QTableWidget::item:selected{
    outline: none开发者_开发百科;
    background-color: #dbe7f4;
    border-radius: 9px;
}

But the result is like this:

How to highlight a row in a QTableWidget with a rounded rectangle?

This is not what I expected. As shown in the picture, every cell in this row is highlighted with a rounded rectangle. But I expect the entire row to be highlighted with a rounded rectangle, which means I want the item in the first row to be 'rounded' in the top-left corner and bottom-left corner, and the item in the third row to be 'rounded' in the top-right corner and bottom-right corner.

Later I tried the qss below:

QTableWidget::item:column(0) {
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    background-color: #dbe7f4;
}
QTableWidget::item:column(2) {
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    background-color: #dbe7f4;
}

However, it is not working. I also tried:

QTableWidget::item:selected:column(0) {
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    background-color: #dbe7f4;
}
QTableWidget::item:selected:column(2) {
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    background-color: #dbe7f4;
}

It is not working either. It just didn't make any difference.

What am I supposed to do? Is there a better way?

0

精彩评论

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