comboModel->setItem(0,0,col0);
comboModel->setItem(0,1,col1);
comboModel->setItem(1,2,col2);
coilView
= new QTableView(this);
// create the tableviewui->comboBox->setView(coilView); // set it to the comboBox before making changes
/* TableView configuration */
/********************/
ui->comboBox->setModel(comboModel); //set the model
coilView->setModel(comboModel);
// connect (ui->comboBox, SIGNAL(activated(int)), this, SLOT(setComboText_2(int))); // this one works but it's not what i want
// connect (coilView, SIGNAL(activated(QModelIndex)), this, SLOT(setComboText(QModelIndex))); // doesn't emit too
comboModel = new QStandardItemModel(5,5);
QStandardItem* col0 = new QStandardItem(QString("t"));
QStandardItem* col1 = new QStandardItem(QString("M"));
QStandardItem* col2 = new QStandardItem(QString("H"));
comboModel->setItem(0,0,col0);
comboModel->setItem(0,1,col1);
comboModel->setItem(1,2,col2);
coilView = new QTableView(this); // create the tableview
ui->comboBox->setView(coilView); // set it to the comboBox before making changes
/* TableView configuration */
coilView->setSelectionMode(QAbstractItemView::SingleSelection);
coilView->setSelectionBehavior(QAbstractItemView::SelectItems);
/********************/
ui->comboBox->setModel(comboModel); //set the model
coilView->setModel(comboModel);
// connect (ui->comboBox, SIGNAL(activated(int)), this, SLOT(setComboText_2(int))); // this one works but it's not what i want
connect (ui->comboBox->view(), SIGNAL(activated(QModelIndex)), this, SLOT(setComboText(QModelIndex)));
// connect (coilView, SIGNAL(activated(QModelIndex)), this, SLOT(setComboText(QModelIndex))); // doesn't emit too
To copy to clipboard, switch view to plain text mode
void MainWindow
::setComboText(const QModelIndex & index
) { // ui->comboBox->setCurrentText(comboModel->data(index).toString()); // commented, because i'm trying to test emmiting of signal by simple code below
std::cout << "hello!";
}
void MainWindow::setComboText(const QModelIndex & index) {
// ui->comboBox->setCurrentText(comboModel->data(index).toString()); // commented, because i'm trying to test emmiting of signal by simple code below
std::cout << "hello!";
}
To copy to clipboard, switch view to plain text mode
Bookmarks