PDA

View Full Version : Set the border's color/style/width of a specified cell in the QTableWidget



ecisp.wangshuo
19th July 2013, 04:12
Hi all,how to set the border's color/style/width of a specified cell in the QTableWidget?:confused:

ChrisW67
19th July 2013, 07:47
You set the row/column width/height by calling QHeaderView::resizeSection() on the horizontalHeader()/verticalheader(). You can have them resize themselves in various ways by using QHeaderView::setResizeMode().

The background, text alignment, font etc. are controlled by data supplied through the model (QTableView) or QTableWidgetItems (QTableWidget). These roles are relevant: Qt::BackgroundRole, Qt::CheckStateRole, Qt::CheckState, Qt::DecorationRole, Qt::FontRole, Qt::TextAlignmentRole, Qt::ForegroundRole

You can implement borders on a cell (separate from the table grid lines) using a QStyledItemDelegate and its paintEvent().

ecisp.wangshuo
19th July 2013, 10:34
You can implement borders on a cell (separate from the table grid lines) using a QStyledItemDelegate and its paintEvent().

Thanks,I know that we should subclass the QStyleItemDelegate and reimplement the paint() and sizeHint() methods.Since I'm just a beginner of Qt,may you provide me a example program what can set the border's color of the specified cell?