Results 1 to 4 of 4

Thread: double clicked on an item QTreeWidget

  1. #1
    Join Date
    Mar 2011
    Location
    Greece
    Posts
    23
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default double clicked on an item QTreeWidget

    I am using QTreeWidget on the MainWindow and items are added to the TreeWidget from a table of a database.The tree has four rows and two columns.When i double click either the root or children on the specific row of the tree,then displays another widget.I am doing this using QModelIndex object.I want only the root of the row to "goes to" the specified widget and not the children.

    My code is:

    //Double click on the treeWidget
    void MainWindow::changeSWidget(QModelIndex index)
    {
    //row 0
    case Tree::Computers://1
    ui->stackedWidget->setCurrentWidget(comp);
    break;
    case Tree::Files://1
    ui->stackedWidget->setCurrentWidget(file);
    break;
    }
    connect(Tree,SIGNAL(loadWidget(QModelIndex)),this, SLOT(changeSWidget(QModelIndex)));

    How can i find which item is clicked ??Doing this when i clicked on each item is called the slot display.
    //double click on treewidget items
    connect(ui->treeWidget,SIGNAL(itemDoubleClicked(QTreeWidgetIt em*,int)),this,SLOT(display(QTreeWidgetItem*,int)) );

    Is it better for me to use a model/view approach??
    i hope you understand what i am saying..
    Last edited by milli; 6th May 2011 at 23:05.

  2. #2
    Join Date
    Apr 2010
    Location
    Sudan
    Posts
    46
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: double clicked on an item QTreeWidget

    How can i find which item is clicked ??
    you can do this by checking the text of the item clicked :

    Qt Code:
    1. void MainWindow::treeViewClicked(QModelIndex index)
    2. {
    3. if(index.data().toString()=="TableRecipts")
    4. createTableReciptsModel();
    5. }
    To copy to clipboard, switch view to plain text mode 

    or, if you have more than row with the same text , you can check both the text and the index :

    Qt Code:
    1. else if(customersTreeValue=="totalBounty"&&index.row()==0)
    2. {
    3. totalBountyClicked();
    4. }
    To copy to clipboard, switch view to plain text mode 

    i hope i was helpful .

  3. The following user says thank you to tinysoft for this useful post:

    milli (7th May 2011)

  4. #3
    Join Date
    Mar 2011
    Location
    Greece
    Posts
    23
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: double clicked on an item QTreeWidget

    your answer helps me to understand how can i do what i wanted...In the treeWidget are stored primary keys of a table and with this piece of code i get the content of the column:
    index.sibling(index.row(),2).data().toInt()

    Thanks a lot again

  5. #4
    Join Date
    Apr 2010
    Location
    Sudan
    Posts
    46
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: double clicked on an item QTreeWidget

    u r welcome
    i am glad that you solved the problem

Similar Threads

  1. Getting the Id of a double clicked item
    By thefatladysingsopera in forum Qt Programming
    Replies: 1
    Last Post: 30th April 2011, 15:18
  2. Replies: 1
    Last Post: 16th December 2009, 03:48
  3. Replies: 12
    Last Post: 24th July 2009, 11:38
  4. Replies: 1
    Last Post: 17th July 2008, 15:42
  5. QTableWidget::item to Double?
    By Afflicted.d2 in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2006, 07:23

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.