简体   繁体   English

将QLineEdit的属性添加到Qt中的QTable窗口小部件

[英]add properties of QLineEdit to QTable Widget in Qt

I want to add a Table Widget in my application. 我想在我的应用程序中添加一个Table Widget But some properties which I want are not supported for Table Widget , but are available for QLineEdit . 但是Table Widget不支持某些我想要的属性,但是QLineEdit可以使用这些属性。 For example Validator , PlaceHolderText , etc properties from QLineEdit . 例如QLineEdit ValidatorPlaceHolderText等属性。 I want to have these properties for individual cells of Table Widget . 我想为Table Widget单个单元格提供这些属性。 I don't want to add QLineEdit in my GUI , only Table Widget . 我不想在我的GUI添加QLineEdit ,仅添加Table Widget Is it possible to do this? 是否有可能做到这一点? Thank You. 谢谢。

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. 创建一个QStyledItemDelegate子类,该子类可以照常绘制文本或占位符文本(无需重新实现即可执行此操作),但是会生成QLineEdit作为其编辑器小部件。

Add it using QTableWidget::setItemDelegate(QAbstractItemDelegate* delegate) . 使用QTableWidget::setItemDelegate(QAbstractItemDelegate* delegate)添加它。

我认为,您可以通过setCellWidget将这些单元格更改为QLineEdit ,并使用其功能:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM