Results 1 to 2 of 2

Thread: selecting a specific QtreeList item

  1. #1
    Join Date
    Mar 2007
    Posts
    74
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default selecting a specific QtreeList item

    What is the proper method for changing the currently selected item in a QTreeList?

    I've specified...
    setSelectionMode(QAbstractItemView::SingleSelectio n);
    setSelectionBehavior(QAbstractItemView::SelectRows );

    I have a function called as shown below:

    connect(m_treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
    this, SLOT(changePage(QTreeWidgetItem *, QTreeWidgetItem *)));

    In some cases I want to ignore the treeclick and Not have the treelist selection change.


    void MainWindow::changePage(QTreeWidgetItem *current, QTreeWidgetItem *previous)
    {
    ....

    // Ignore click in tree and keep the selection on the currently selected item...
    current->setSelected(false);
    m_treeWidget->setCurrentItem(previous);
    update();


    }


    This now selects everything between current and previous.

    As I have called:

    setSelectionMode(QAbstractItemView::SingleSelectio n);
    setSelectionBehavior(QAbstractItemView::SelectRows );

    I don't see how this should even be possible. I can't make multiple selections
    or a range of selections manually from the tree...

  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: selecting a specific QtreeList item

    Current item and selected item are two different concepts. You can connect to the selectionChanged signal of the item selection model (you have to retrieve it first from the view) and have both the old and new selections available. Then you can reapply the old selection if you want.

Similar Threads

  1. QListWidget and selecting an item
    By invictus in forum Newbie
    Replies: 4
    Last Post: 19th June 2007, 11:59
  2. Replies: 1
    Last Post: 17th March 2006, 08:19

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.