简体   繁体   中英

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* 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.

  1. Firstly you create your QComboBox
  2. then call void QTableWidget::setCellWidget ( int row, int column, QWidget * widget )

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

Maybe you want to add a widget to a QTableWidget with

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

and accessing it by

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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