user3457200
user3457200

Reputation: 129

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.

Upvotes: 4

Views: 3073

Answers (2)

Salvatore Avanzo
Salvatore Avanzo

Reputation: 2786

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

Upvotes: 2

Ferenc Deak
Ferenc Deak

Reputation: 35448

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

Upvotes: 6

Related Questions