我使用一个简单的QTableWidget
来显示一些QTableWidgetItems
,如下所示:
+-------------+-------------+
| | some text 1 |
| some number +-------------+
| | some text 2 |
+-------------+-------------+
| | some text 1 |
| some number +-------------+
| | some text 2 |
+-------------+-------------+
我知道可以通过为QTableWidgetItems
设置样式表来在QTableWidget
周围绘制边框,如下所示
QTableView::item {
border-bottom: 1px solid black;
}
但这适用于所有的QTableWidgetItems
。我只想绘制“一些数字”和“一些文本2”项目的边界。
在坚持使用QTableWidget
和QTableWisgetItem
的同时,是否可以做到这一点?我不能使用set QObject::setProperty
属性来标识样式表中的项,因为QTableWidgetItem
不是QObject
的…。
发布于 2017-08-09 05:53:48
使用委托,示例
class MyDelegate : public QItemDelegate
{
public:
MyDelegate( QObject *parent ) : QItemDelegate( parent ) { }
void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
};
void MyDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
QItemDelegate::paint( painter, option, index );
painter->setPen( Qt::red );
painter->drawLine( option.rect.topLeft(), option.rect.bottomLeft() );
// What line should you draw
// painter->drawLine( option.rect.topLeft(), option.rect.topRight() );
// painter->drawLine( option.rect.topLeft(), option.rect.bottomLeft() );
}
...
m_TableWidgetClass->setItemDelegateForRow(row, new MyDelegate( this));
//m_TableWidgetClass->setItemDelegateForColumn(column, new MyDelegate( this));
https://stackoverflow.com/questions/45577434
复制相似问题