Results 1 to 3 of 3

Thread: How to use QTreeView in QComboBox?

  1. #1
    Join Date
    Feb 2007
    Location
    Russia, Novosibirsk
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How to use QTreeView in QComboBox?

    I try to do something like this (original code was written in Python, so may be it has some syntax errors):
    Qt Code:
    1. QTreeView *tvGroups = new QTreeView()
    2. MyModel *groupModel = new MyModel()
    3. cb->setView(&tvGroups)
    4. cb->setModel(&groupModel)
    5. cb->setModelColumn(0)
    To copy to clipboard, switch view to plain text mode 
    cb is QComboBox.
    After it usual integer combobox indexes become very strange.
    In function which is connected to signal setCurrentIndex(int index) I print index and see that it has value -1 for items group2 and something_else, and 0 for others in the tree example below.
    tree has such items:
    Qt Code:
    1. All
    2. group1
    3. group1.1
    4. group1.2
    5. group2
    6. something_else
    To copy to clipboard, switch view to plain text mode 
    What is wrong?

  2. #2
    Join Date
    Jun 2007
    Posts
    2

    Default Re: How to use QTreeView in QComboBox?

    You need to set the model first on the treeview.
    treeview->setModel(model)
    and then tell the combobox to use that model.

    Or you can just use QTreeWidget directly using default model :

    Qt Code:
    1. QTreeWidget *tree = new QTreeWidget();
    2. cb->setModel( tree->model());
    3. cb->setView ( tree);
    4.  
    5. add a few items (QTreeWidgetItem) to you tree and see if that works for you
    To copy to clipboard, switch view to plain text mode 

    Sid

  3. #3
    Join Date
    Jun 2007
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to use QTreeView in QComboBox?

    I am also trying to use a QTreeWidget inside of a QComboBox (although using PyQt). I did what was suggested (although in my case, I subclass QComboBox), but my issue is that when I click on the combo box, it opens up with only one line that is not scrollable except using the mouse wheel. Clicking on any of the other entries results in the first entry being displayed or no entry being displayed.

    Any idea on how to fix this?

    Thanks.

Similar Threads

  1. QTreeView repaint
    By graeme in forum Qt Programming
    Replies: 17
    Last Post: 13th March 2012, 13:27
  2. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 16:14
  3. QDataWidgetMapper <=> QComboBox best practice
    By saknopper in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 10:50
  4. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 06:25
  5. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 14:24

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
  •  
Qt is a trademark of The Qt Company.