Results 1 to 4 of 4

Thread: QTreeWidgetItem selection

  1. #1
    Join Date
    Sep 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeWidgetItem selection

    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

    Qt Code:
    1. void MainWindow::DocumentTable()
    2. {
    3. tableview = new QTableView;
    4. query = new QSqlQueryModel(this);
    5.  
    6. foreach(it,treeWidget->selectedItems())
    7. {
    8. for (int col=0; col< it->columnCount(); ++col)
    9. {
    10. qDebug() << col << it->text(col);
    11.  
    12. QSqlQuery qry;
    13. qry.prepare("select * from document where Folno=:Folno");
    14. qry.bindValue(":Folno", it->text(col));
    15. qry.exec();
    16.  
    17. query->setQuery(qry);
    18.  
    19. tableview->setModel(query);
    20. tableview->setEditTriggers(QAbstractItemView::NoEditTriggers);
    21. tableview->show();
    22.  
    23. Docwidget= new QDockWidget(this);
    24. Docwidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    25.  
    26. Docwidget->setWidget(tableview);
    27. addDockWidget(Qt::RightDockWidgetArea,Docwidget);
    28. Docwidget->show();
    29.  
    30.  
    31. if(!query->submit())
    32. {
    33. qDebug() << "Error " << query->lastError().text();
    34. }
    35.  
    36. db.close();
    37.  
    38. }
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 

    any ideas ??

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidgetItem selection

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidgetItem selection

    Thank you very much wysota.
    Could you please give a hint or any idea to start. i'm stuck .

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidgetItem selection

    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 11
    Last Post: 3rd March 2012, 22:21
  2. qtreewidgetitem
    By ahmetturan in forum Newbie
    Replies: 1
    Last Post: 24th July 2011, 19:38
  3. QTreeWidgetItem
    By bismitapadhy in forum Qt Programming
    Replies: 12
    Last Post: 7th January 2011, 10:48
  4. Replies: 5
    Last Post: 23rd September 2010, 13:58
  5. QTreeWidgetItem
    By Sarma in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2006, 19:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.