PDA

View Full Version : QTreeWidgetItem selection



sara1987
6th September 2012, 08:03
Hi guys

In this function im trying to connect each QTreeWidgetItem with its corresponding query,
once i select an item a query result in tableview model is shown.

what i want is that when i select a new item the shown tableview hide and new one appears with a new result. what i have until now is that each item i select a new tableview appears . I want to see only one tableview.

here is my function


void MainWindow::DocumentTable()
{
tableview = new QTableView;
query = new QSqlQueryModel(this);

foreach(it,treeWidget->selectedItems())
{
for (int col=0; col< it->columnCount(); ++col)
{
qDebug() << col << it->text(col);

QSqlQuery qry;
qry.prepare("select * from document where Folno=:Folno");
qry.bindValue(":Folno", it->text(col));
qry.exec();

query->setQuery(qry);

tableview->setModel(query);
tableview->setEditTriggers(QAbstractItemView::NoEditTriggers) ;
tableview->show();

Docwidget= new QDockWidget(this);
Docwidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);

Docwidget->setWidget(tableview);
addDockWidget(Qt::RightDockWidgetArea,Docwidget);
Docwidget->show();


if(!query->submit())
{
qDebug() << "Error " << query->lastError().text();
}

db.close();

}
}
}


any ideas ?? :)

wysota
8th September 2012, 07:00
But what exactly is the problem? You want to hide the previous table? So maybe you should reuse the one that you already have instead of creating a new one each time.

sara1987
8th September 2012, 13:01
Thank you very much wysota.
Could you please give a hint or any idea to start. i'm stuck .

wysota
9th September 2012, 11:03
I can't give you a hint unless you tell me what your problem is. So far you didn't ask any question (apart "any ideas?" which does not describe what your problem is).