Results 1 to 5 of 5

Thread: [+] does not show up immediately

  1. #1
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question [+] does not show up immediately

    I have a slight problem displaying [+] signs in a standard tree view.

    The view is connected to a custom tree model. The model is initially empty. When rowCount() for some tree node is called first time the model submits a request to a separate thread using a queued connection and returns 0. The thread in the meantime loads data from the database and sends a response back to the model, aslo using a queued connection. When the model processes the response on the GUI thread, it calls beginInsertRows(), inserts the node's children and calls endInsertRows(). But [+] sing does not show up under the corresponding node in the tree view. However, as soon as I change focus to another window the [+] sign appears at the right place.

    Just wanted to ask if anyone has experienced similar problem? Is there a way make [+] sing appear right away?

    PS: I verified that when endInsertRows() is called, rowCount() is also called before endInsertRows() returns, and this rowCount() call returns correct number of rows, namely, the number of records retrieved from the database.

    PPS: I also move tree nodes around using drag/drop. Re-parenting also goes through the same path: tree view -> tree model -> thread -> database ->thread ->tree model -> tree view. When a response arrives to the tree model, the model removes the moved node from the old position and inserts it to a new position. And there is no problem displaying [+] signs by the tree view in this scenario, it only manifests itself when the model is initially populated.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [+] does not show up immediately

    may be u can try calling model->reset() after u populate data.

  3. #3
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [+] does not show up immediately

    This is a very good point. I actually forgot to mention that I tried calling model->reset() and the [+] signs appear properly, but the problem with this is, in addition to performance penalty, the view looses current selection. Since the model populated incrementally, I expand some node while it is selected, and suddenly selection disappears. This becomes especially annoying when I use a keyboard instead of a mouse.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [+] does not show up immediately

    How about emit dataChanged() instead of reset() ??
    I dont think dataChanged() removes the selection.
    I am not very good at model/view, but emit dataChanged had worked for me in one case.

  5. The following user says thank you to aamer4yu for this useful post:

    yuriry (4th October 2008)

  6. #5
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [+] does not show up immediately

    Unbelievable, thank you so much! Emitting dataChanged() on the parent after calling beginInsertRows()/endInsertRows() on the same parent did the work!

    What's interesting is if I turn queued connection into direct connection, thus by-passing the thread and calling the database synchronously, everything works. It only did not work with asynchronous database requests, but dataChanged() solved this. Thank you again!

Similar Threads

  1. The show() method...
    By salmanmanekia in forum Qt Programming
    Replies: 8
    Last Post: 18th June 2008, 07:32
  2. How to show custom widget in TreeView's cell :-/
    By WolfMM in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2007, 11:16
  3. How to show a "widget" immediately?
    By deweyjew in forum Newbie
    Replies: 2
    Last Post: 31st May 2006, 12:58
  4. WYSIWYG html, Window show png icon mac no!
    By patrik08 in forum Qt Programming
    Replies: 10
    Last Post: 25th May 2006, 12:01
  5. QtSingleApplication
    By mule in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2006, 19:21

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.