#include <QtGui>
int main(int argc, char *argv[])
{
// Create a TableWidget
// Add Table Widget to main window
widget.layout()->addWidget(tableWidget);
// Make TableWidget to 2 Rows x 2 Columns
tableWidget->setColumnCount(2); // This is required
tableWidget->setRowCount(2); // Do this or call tableWidget->insertRow() later
// Add 4 Items to the TableWidget
// Prepare ComboBox
comboBox
->addItems
(QStringList() <<
"Option 1" <<
"Option 2" <<
"Option 3" <<
"Option 4");
// Add ComboBox at 1st row 1st column of TableWidget
tableWidget->setCellWidget(0, 0, comboBox);
// Show main window
widget.show();
return a.exec();
}
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget widget;
widget.setLayout(new QGridLayout(&widget));
// Create a TableWidget
QTableWidget* tableWidget = new QTableWidget(&widget);
// Add Table Widget to main window
widget.layout()->addWidget(tableWidget);
// Make TableWidget to 2 Rows x 2 Columns
tableWidget->setColumnCount(2); // This is required
tableWidget->setRowCount(2); // Do this or call tableWidget->insertRow() later
// Add 4 Items to the TableWidget
tableWidget->setItem(0, 0, new QTableWidgetItem("Row 1, Col: 1"));
tableWidget->setItem(0, 1, new QTableWidgetItem("Row 1, Col: 2"));
tableWidget->setItem(1, 0, new QTableWidgetItem("Row 1, Col: 1"));
tableWidget->setItem(1, 1, new QTableWidgetItem("Row 2, Col: 2"));
// Prepare ComboBox
QComboBox *comboBox = new QComboBox(&widget);
comboBox->addItems(QStringList() << "Option 1" << "Option 2" << "Option 3" << "Option 4");
// Add ComboBox at 1st row 1st column of TableWidget
tableWidget->setCellWidget(0, 0, comboBox);
// Show main window
widget.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks