Results 1 to 5 of 5

Thread: Repaint QTreeWidget

  1. #1
    Join Date
    Aug 2006
    Location
    Ulm/Germany
    Posts
    3
    Platforms
    Unix/X11

    Default Repaint QTreeWidget

    Hi,

    I'm experimenting with qtjambi at the moment and I'm writing a little Jabberclient.
    For the display of the roster (contact list) I'm using a QTreeWidget.
    I've implemented a listener to react on any events which affect the roster:

    Qt Code:
    1. public void presenceChanged(String user)
    2. {
    3. parent.setText(0, user);
    4. getTree().addTopLevelItem(parent);
    5. System.out.println(user);
    6. }
    To copy to clipboard, switch view to plain text mode 

    The listener itself is working correctly, but after initially connect to the server (so the listener is called >50times), my QTreeWidget is only showing the first 3-4 items. After clicking on the column-header for resorting the Tree-Items all Items were shown. So this seems to be a repaint-problem.
    I've tried to add "getTree().repaint()" or "getTree().update()" within the listener, but none helped.
    The debug-ouput is "QObject::connect: Cannot queue arguments of type 'QModelIndex'", but I have no idea if this is part of the problem above (I'm new to QT at all).

    Any hints? Thx.

    Greets,
    Ace

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Repaint QTreeWidget

    The nature of the warning message you get implies that you're probably using a separate thread somewhere. Are you sure you need it, because I don't think so...

    About the error itself, it's hard to say anything without seeing more code. As you are using QTreeWidget and not QTreeView, you shouldn't access model indexes yourself, so I take it that you got that message from some internal Qt code or did you use QModelIndex somewhere?

  3. #3
    Join Date
    Aug 2006
    Location
    Ulm/Germany
    Posts
    3
    Platforms
    Unix/X11

    Default Re: Repaint QTreeWidget

    Hi,

    Quote Originally Posted by wysota
    The nature of the warning message you get implies that you're probably using a separate thread somewhere. Are you sure you need it, because I don't think so...
    No, there's no other Thread.

    Quote Originally Posted by wysota
    About the error itself, it's hard to say anything without seeing more code. As you are using QTreeWidget and not QTreeView, you shouldn't access model indexes yourself, so I take it that you got that message from some internal Qt code or did you use QModelIndex somewhere?
    I've created the MainWindow with designer and I must admit, that using of QTreeWidget insteand of QTreeView was a coincidence, because I don't really know what's the difference between these widgets.
    And no, I'm not using QModelIndex anywhere.

    Your request for more code, well, there isn't much more. As said above I created the MainWindow with designer, so my MainWindow-Class is:

    Qt Code:
    1. public class MainWindow extends QMainWindow
    2. {
    3. private Ui_MainWindow ui = new Ui_MainWindow();
    4. private JJabRoster roster;
    5. private XMPPConnection con;
    6.  
    7. public MainWindow()
    8. {
    9. ui.setupUi(this);
    10. try
    11. {
    12. con = new XMPPConnection("macht-locker.de");
    13. con.login("hanf", "password");
    14. }
    15. catch(XMPPException e)
    16. {
    17. System.err.println("Error: "+e.getMessage());
    18. System.exit(1);
    19. }
    20. roster = new JJabRoster(con, ui.rosterTree,
    21. ui.actionHide_empty_Groups.isChecked(), ui.actionHide_Offline_Contacts.isChecked());
    22. ui.actionHide_Offline_Contacts.toggled.connect(roster,"toggleHideOfflineContacts(boolean)");
    23. ui.actionHide_empty_Groups.toggled.connect(roster,"toggleHideEmptyGroups(boolean)");
    24.  
    25. ui.rosterTree.itemDoubleClicked.connect(roster, "createChat(int)");
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    And the JJabRoster-Class:
    Qt Code:
    1. public class JJabRoster extends QObject
    2. {
    3. private LinkedList<RosterGroup> groups;
    4. private QTreeWidget tree;
    5. private XMPPConnection con;
    6. private Roster roster;
    7. private boolean hideEmptyGroups;
    8. private boolean hideOfflineContacts;
    9.  
    10. public JJabRoster(XMPPConnection con, QTreeWidget tree, boolean hideEmptyGroups, boolean hideOfflineContacts)
    11. {
    12. this.tree = tree;
    13. this.con = con;
    14. this.roster = con.getRoster();
    15. this.roster.addRosterListener(new RosterListener() {
    16.  
    17. public void rosterModified(Collection addresses)
    18. {
    19. System.out.println("roster modified: "+addresses.toString());
    20. }
    21.  
    22. public void presenceChanged(String user)
    23. {
    24. parent.setText(0, user);
    25. getTree().addTopLevelItem(parent);
    26. System.out.println(user);
    27. }
    28.  
    29. public void entriesUpdated(Collection addresses)
    30. {
    31. System.out.println("entries updated: "+addresses.toString());
    32. }
    33.  
    34. public void entriesDeleted(Collection addresses)
    35. {
    36. System.out.println("entries deleted: "+addresses.toString());
    37. }
    38.  
    39. public void entriesAdded(Collection addresses)
    40. {
    41. System.out.println("entries added: "+addresses.toString());
    42. }
    43. });
    44.  
    45. this.hideEmptyGroups = hideEmptyGroups;
    46. this.hideOfflineContacts = hideOfflineContacts;
    47. groups = new LinkedList<RosterGroup>();
    48. for(Iterator<RosterGroup> it = roster.getGroups();it.hasNext();)
    49. groups.add(it.next());
    50.  
    51. }
    52.  
    53. public LinkedList<RosterGroup> getGroups()
    54. {
    55. return groups;
    56. }
    57.  
    58. public List<RosterEntry> getEntriesForGroup(RosterGroup group)
    59. {
    60. LinkedList<RosterEntry> list = new LinkedList<RosterEntry>();
    61. for(Iterator<RosterEntry> it = group.getEntries(); it.hasNext();)
    62. list.add(it.next());
    63. return list;
    64. }
    65. public void toggleHideEmptyGroups(boolean hide)
    66. {
    67. this.hideEmptyGroups = hide;
    68. }
    69.  
    70. public void toggleHideOfflineContacts(boolean hide)
    71. {
    72. this.hideOfflineContacts = hide;
    73. }
    74.  
    75. public Roster getRoster()
    76. {
    77. return roster;
    78. }
    79.  
    80. public QTreeWidget getTree()
    81. {
    82. return tree;
    83. }
    84.  
    85.  
    86. }
    To copy to clipboard, switch view to plain text mode 

    And to be complete my JJabRosterEntry-Class:
    Qt Code:
    1. public class JJabRosterEntry extends QTreeWidgetItem
    2. {
    3.  
    4. private RosterEntry entry;
    5.  
    6. public JJabRosterEntry(QTreeWidgetItem parent, RosterEntry entry)
    7. {
    8. super(parent);
    9. this.entry = entry;
    10. String bareJID = StringUtils.parseBareAddress(entry.getUser());
    11. try
    12. {
    13. this.setText(0,entry.getName());
    14. }
    15. catch(NullPointerException e)
    16. {
    17. this.setText(0, bareJID);
    18. }
    19. this.setToolTip(0, entry.getUser());
    20.  
    21. }
    22.  
    23. public RosterEntry getEntry() {
    24. return entry;
    25. }
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 

    Greets,
    Ace
    Last edited by jacek; 8th August 2006 at 21:15. Reason: splitted too long line

  4. #4
    Join Date
    Aug 2006
    Location
    Ulm/Germany
    Posts
    3
    Platforms
    Unix/X11

    Default Re: Repaint QTreeWidget

    Anywhere else anybody with a hint for me?

    Greets,
    Ace

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Repaint QTreeWidget

    What about the code for createChat(int), Roster, RosterEntry? Do you use JJabRosterEntry anywhere? I can't seem to locate creating any instances of it in your code...

Similar Threads

  1. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 06:50
  2. force repaint
    By georgie in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2006, 13:16
  3. How to capture resizing of QTreeWidget columns?
    By simk in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2006, 06:10
  4. QTreeWidget problem!!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2006, 11:47
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32

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.