qss文件中 单独设置最后一列
时间: 2024-03-02 17:51:15 浏览: 28
可以使用 `QTableView::setItemDelegateForColumn()` 函数来为表格的某一列设置委托。对于最后一列,可以通过重写 `QStyledItemDelegate` 的 `paint()` 函数来自定义该列的样式,代码如下:
```cpp
class LastColumnDelegate : public QStyledItemDelegate
{
public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
{
// 自定义最后一列的样式
if (index.column() == index.model()->columnCount() - 1) {
// ...
} else {
QStyledItemDelegate::paint(painter, option, index);
}
}
};
// 在需要设置的表格上设置委托
ui->tableView->setItemDelegateForColumn(column, new LastColumnDelegate);
```
这里假设要设置的表格是 `tableView`,同时要设置的是最后一列。通过重写 `paint()` 函数,在自定义最后一列的样式时,可以使用 `painter` 对象对该列进行绘制。在其他列时,调用 `QStyledItemDelegate::paint()` 函数绘制默认样式。最后,通过 `setItemDelegateForColumn()` 函数将委托设置给指定的列。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)