简体   繁体   English

问:如何在QTableWidgetItem中显示QComboBox?

[英]Qt: How to display QComboBox inside QTableWidgetItem?

I'm trying to display a QComboBox inside a QTableWidgetItem by setting it as its child, using this code: 我正在尝试通过将QComboBox设置为其子项来在QTableWidgetItem中显示它,使用以下代码:

QComboBox* qcb;
int r,c;
//......
qcb->setParent((QWidget*)tableWidget->item(r,c));

but that didn't the job. 但那不是工作。

so how to fix that? 那怎么解决? thanks. 谢谢。

You do this via the QTableWidget object itself. 您可以通过QTableWidget对象本身执行此操作。

  1. Firstly you create your QComboBox 首先,您创建您的QComboBox
  2. then call void QTableWidget::setCellWidget ( int row, int column, QWidget * widget ) 然后调用void QTableWidget::setCellWidget ( int row, int column, QWidget * widget )

http://qt-project.org/doc/qt-4.8/qtablewidget.html#setCellWidget http://qt-project.org/doc/qt-4.8/qtablewidget.html#setCellWidget

Maybe you want to add a widget to a QTableWidget with 也许你想用QTableWidget添加一个小部件

void QTableWidget::setCellWidget ( int row, int column, QWidget * widget )

and accessing it by 并通过访问它

QWidget * QTableWidget::cellWidget ( int row, int column ) const

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

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