Answer the question
In order to leave comments, you need to log in
Qt C++ listWidget how to highlight the first line and get the text of the selected line?
It is necessary after the loading into the list of strings, immediately select 1 element. How?
// Очистить список строк
ui->listWidget->clear();
//Осуществляем запрос
QSqlQuery query;
query.exec("select name from sqlite_master where type='table'");
while (query.next())
{
QString table = query.value(0).toString();
ui->listWidget->addItem(table);
}
// Обновить таблицу
void MainWindow::table_now()
{
// Очистить таблицу
ui->tableWidget->clearContents();
ui->tableWidget->setRowCount(0);
Получить текст выделенного элемента!
// Вывод в таблицу
QSqlQuery query;
query.exec("select id,name,comment from `Текст Элемента`");
while (query.next())
{
ui->tableWidget->insertRow(ui->tableWidget->rowCount());
for (int i=0; i<3; i++){
QTableWidgetItem * item = new QTableWidgetItem(query.value(i).toString());
ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,i,item);
}
}
}
Answer the question
In order to leave comments, you need to log in
It is necessary after the loading into the list of strings, immediately select 1 element. How?QListWidget::setCurrentRow ?
And how to get the text of the selected element?QListWidget::currentItem ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question