Qt: How to display a QComboBox inside a QTableWidgetItem?

Im 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 it did not help.

so how to fix it? thank.

+4
source share
2 answers

You do this through the object itself QTableWidget.

  • First, you create your QComboBox
  • then call void QTableWidget::setCellWidget ( int row, int column, QWidget * widget )

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

+4
source

Perhaps you want to add a widget to a QTableWidget using

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

and access it using

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

Source: https://habr.com/ru/post/1533238/


All Articles