Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: How to display QComboBox inside QTableWidgetItem?

Tags:

c++

qt

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.

like image 380
user3457200 Avatar asked Feb 14 '23 10:02

user3457200


2 Answers

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

like image 186
Ferenc Deak Avatar answered Feb 16 '23 02:02

Ferenc Deak


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
like image 35
Salvatore Avanzo Avatar answered Feb 16 '23 01:02

Salvatore Avanzo