Results 1 to 2 of 2

Thread: can't select item in a QTreeWidget via code

  1. #1
    Join Date
    Feb 2009
    Posts
    20

    Default can't select item in a QTreeWidget via code

    I have a QCombox and in the combobo a TreeWidget
    Qt Code:
    1. comboBox->setModel(treeWidget->model());
    2. comboBox->setView(treeWidget);
    To copy to clipboard, switch view to plain text mode 

    Now I want to pre select an item in this treeWidget
    Qt Code:
    1. treeWidget->scrollToItem (Item);
    2. treeWidget->setCurrentItem(Item);
    To copy to clipboard, switch view to plain text mode 

    But for some reason, it doesn't select the Item.
    In the combobox is still the first toplevelItem visible and when I click on the combobox he opens the correct toplevelitem, where Item is placed, but it's not selected.

    Is it a bug, or am I on the wrong way?
    Last edited by zack; 14th July 2009 at 12:06.

  2. #2
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: can't select item in a QTreeWidget via code

    Instead of this:
    Qt Code:
    1. treeWidget->scrollToItem (Item);
    2. treeWidget->setCurrentItem(Item);
    To copy to clipboard, switch view to plain text mode 

    You should set correct index on your QComboBox:
    Qt Code:
    1. comboBox->setCurrentIndex(treeWidget->indexOfTopLevelItem(Item));
    To copy to clipboard, switch view to plain text mode 

    Anyway, why do you want to put a QTreeWidget into a combo box? IMHO if you have a tree structure it won't be nice. And if you don't have a tree structure, what's the point of using QTreeWidget here?
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

Similar Threads

  1. QTreeWidget select item
    By ^NyAw^ in forum Qt Programming
    Replies: 7
    Last Post: 26th October 2007, 14:26
  2. Inserting Item to a QTreeWidget from Thread?
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2007, 11:23
  3. Cannot select an item in QComboBox
    By Declan in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2007, 08:08
  4. QTreeWidget item editing: want column specificity
    By McKee in forum Qt Programming
    Replies: 12
    Last Post: 10th December 2006, 22:12
  5. Removing items properly from qtreewidget item
    By Djony in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2006, 12:20

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.