Cool_Coder
Cool_Coder

Reputation: 5073

add properties of QLineEdit to QTable Widget in Qt

I want to add a Table Widget in my application. But some properties which I want are not supported for Table Widget, but are available for QLineEdit. For example Validator, PlaceHolderText, etc properties from QLineEdit. I want to have these properties for individual cells of Table Widget. I don't want to add QLineEdit in my GUI, only Table Widget. Is it possible to do this? Thank You.

Upvotes: 0

Views: 1301

Answers (2)

masoud
masoud

Reputation: 56479

I think, you can change those cells to be a QLineEdit by setCellWidget, and use its functionality :

the_table_widget->setCellWidget(row, col, new QLineEdit);

Upvotes: 1

cmannett85
cmannett85

Reputation: 22346

Create a QStyledItemDelegate subclass that draws the text or placeholder text as normal (it can do this without reimplementing), but produces a QLineEdit as it's editor widget.

Add it using QTableWidget::setItemDelegate(QAbstractItemDelegate* delegate).

Upvotes: 3

Related Questions