Results 1 to 4 of 4

Thread: moving QTreeWidgetItem

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default moving QTreeWidgetItem

    Hi,

    I have a QTreeWidget that is represented like this:

    Column0 Column1
    Item1
    Item2
    |-------------SubItem1 [Button1]
    |-------------SubItem2 [Button2]

    Internally I have a data structure that contains the same data.
    Now, I use a method that let's me move SubItem1 and SubItem2 up or down internally in my structure data. When I finish the internal data moving I want to move the items of the QTreeWidget.
    So what I am doing now is to take all the subItems into a QList<QTreeWidgetItem*> and then I reinsert them as Item2 childs following the internal data structure. This works well but there is a problem, all the Widgets that the SubItems have are lost. So the Button1 and Button2 have dissapeared and only the text of the buttons are displayed.

    Is there any other way to do this? Or how can I solve this problem?

    Thanks,
    Òscar Llarch i Galán

  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: moving QTreeWidgetItem

    I would suggest switching to the model approach. It's a big step to take at once but you are currently reaching a point when using the simplified interface of QTreeWidget becomes a burden instead of a simplification. If you implement the model correctly, it will work directly on your internal representation and doing such things as moving the items will become a matter of emitting one or two signals and nothing more.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: moving QTreeWidgetItem

    Hi,

    Thanks wysota. I know that witching to the model approach will be better but currently I can't because I have no much time to spend on this. This is a big application and create the code to make it work on model approach will need much time.

    Thanks,
    Òscar Llarch i Galán

  4. #4
    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: moving QTreeWidgetItem

    It still might require less time than battling against your current architecture.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Custom QTreeWidgetItem context menu?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 1st February 2010, 04:42
  2. Replies: 3
    Last Post: 26th April 2008, 18:42
  3. select a QTreeWidgetItem
    By mattia in forum Newbie
    Replies: 2
    Last Post: 21st December 2007, 11:01
  4. Replies: 4
    Last Post: 19th October 2007, 19:47
  5. QTreeWidgetItem swap or move up one level problem
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2006, 18:34

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.