Results 1 to 5 of 5

Thread: QComboBox with a tree model - adding items problem.

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QComboBox with a tree model - adding items problem.

    Hi,

    I have an editable QComboBox, that I use to show a children list of a single leaf of a tree model.
    Which means:
    Qt Code:
    1. myCoboBox->setModel(myTreeModel);
    2. myCoboBox->setRootIndex(index); //the index is the QModelIndex of a child item in the tree
    To copy to clipboard, switch view to plain text mode 

    This works well, the combo box shows a list of children of the item who's index I set in the setRootIndex().

    The problem I am having is with adding new items via the editable lineedit.
    When I type in a new item which does not exist in the list the combo box is showing, and hit enter, the item gets added to the model - however, not as a child of the combo's root index as I expected, but as a child of the root index of the tree model.
    I have connected a slot to the model's rowsInserted() and indeed the combo box adds the item with an invalid QModelIndex (which means the root index of the model).

    My question is:
    Since QComboBox does hold the notion of working with a specific level of an hierarchical model, my first thought is that I might have missed something in the way I am using it to add a new item.
    I have read QComboBox's documentation and could not find anything I might have missed - but that does not mean I didn't.
    I could add my own custom delegate to the combo box's line edit and there make sure that the insertion is done right, but if there is a "out of the box" way to do it which I missed, that would be better.

    Thanks in advance!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox with a tree model - adding items problem.

    That sounds like a bug to me.

    Cheers,
    _

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

    high_flyer (16th January 2017)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox with a tree model - adding items problem.

    I have submited the bug, and a patch, in case someone stumbles on this.
    https://bugreports.qt.io/browse/QTBUG-58313
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox with a tree model - adding items problem.

    I don't think the Qt project an accept patches that do not go through Gerrit, mostly for legal reasons.

    Anyway, good find!

    Cheers,
    _

  6. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox with a tree model - adding items problem.

    I know - the patch is there to help the assigned developer.
    I didn't have the time to commit to gerrit my self yet, need to bring my repo up to date and to configuring it for gerrit, run tests etc.
    Will see what comes earlier, me committing to gerrit, or them using my submission ;-)
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QComboBox extremely slow on adding a lot of items
    By Buldozer in forum Qt Programming
    Replies: 3
    Last Post: 16th May 2021, 13:46
  2. Replies: 1
    Last Post: 20th June 2013, 07:24
  3. Adding new items to model (MVC)
    By Urvin in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2010, 08:54
  4. Multible QCombobox tree with model view
    By mrandreas in forum Newbie
    Replies: 2
    Last Post: 22nd September 2010, 15:00
  5. [QT3] QComboBox: Disable adding items on Enter-keypress
    By BrainB0ne in forum Qt Programming
    Replies: 7
    Last Post: 14th January 2006, 20:43

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.