PDA

View Full Version : Repaint QTreeWidget



AceTheFace
7th August 2006, 10:24
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:



public void presenceChanged(String user)
{
QTreeWidgetItem parent = new QTreeWidgetItem();
parent.setText(0, user);
getTree().addTopLevelItem(parent);
System.out.println(user);
}


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

wysota
7th August 2006, 12:04
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?

AceTheFace
7th August 2006, 12:17
Hi,


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.


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:



public class MainWindow extends QMainWindow
{
private Ui_MainWindow ui = new Ui_MainWindow();
private JJabRoster roster;
private XMPPConnection con;

public MainWindow()
{
ui.setupUi(this);
try
{
con = new XMPPConnection("macht-locker.de");
con.login("hanf", "password");
}
catch(XMPPException e)
{
System.err.println("Error: "+e.getMessage());
System.exit(1);
}
roster = new JJabRoster(con, ui.rosterTree,
ui.actionHide_empty_Groups.isChecked(), ui.actionHide_Offline_Contacts.isChecked());
ui.actionHide_Offline_Contacts.toggled.connect(ros ter,"toggleHideOfflineContacts(boolean)");
ui.actionHide_empty_Groups.toggled.connect(roster,"toggleHideEmptyGroups(boolean)");

ui.rosterTree.itemDoubleClicked.connect(roster, "createChat(int)");
}
}


And the JJabRoster-Class:


public class JJabRoster extends QObject
{
private LinkedList<RosterGroup> groups;
private QTreeWidget tree;
private XMPPConnection con;
private Roster roster;
private boolean hideEmptyGroups;
private boolean hideOfflineContacts;

public JJabRoster(XMPPConnection con, QTreeWidget tree, boolean hideEmptyGroups, boolean hideOfflineContacts)
{
this.tree = tree;
this.con = con;
this.roster = con.getRoster();
this.roster.addRosterListener(new RosterListener() {

public void rosterModified(Collection addresses)
{
System.out.println("roster modified: "+addresses.toString());
}

public void presenceChanged(String user)
{
QTreeWidgetItem parent = new QTreeWidgetItem();
parent.setText(0, user);
getTree().addTopLevelItem(parent);
System.out.println(user);
}

public void entriesUpdated(Collection addresses)
{
System.out.println("entries updated: "+addresses.toString());
}

public void entriesDeleted(Collection addresses)
{
System.out.println("entries deleted: "+addresses.toString());
}

public void entriesAdded(Collection addresses)
{
System.out.println("entries added: "+addresses.toString());
}
});

this.hideEmptyGroups = hideEmptyGroups;
this.hideOfflineContacts = hideOfflineContacts;
groups = new LinkedList<RosterGroup>();
for(Iterator<RosterGroup> it = roster.getGroups();it.hasNext();)
groups.add(it.next());

}

public LinkedList<RosterGroup> getGroups()
{
return groups;
}

public List<RosterEntry> getEntriesForGroup(RosterGroup group)
{
LinkedList<RosterEntry> list = new LinkedList<RosterEntry>();
for(Iterator<RosterEntry> it = group.getEntries(); it.hasNext();)
list.add(it.next());
return list;
}
public void toggleHideEmptyGroups(boolean hide)
{
this.hideEmptyGroups = hide;
}

public void toggleHideOfflineContacts(boolean hide)
{
this.hideOfflineContacts = hide;
}

public Roster getRoster()
{
return roster;
}

public QTreeWidget getTree()
{
return tree;
}


}

And to be complete my JJabRosterEntry-Class:


public class JJabRosterEntry extends QTreeWidgetItem
{

private RosterEntry entry;

public JJabRosterEntry(QTreeWidgetItem parent, RosterEntry entry)
{
super(parent);
this.entry = entry;
String bareJID = StringUtils.parseBareAddress(entry.getUser());
try
{
this.setText(0,entry.getName());
}
catch(NullPointerException e)
{
this.setText(0, bareJID);
}
this.setToolTip(0, entry.getUser());

}

public RosterEntry getEntry() {
return entry;
}

}

Greets,
Ace

AceTheFace
8th August 2006, 21:52
Anywhere else anybody with a hint for me?

Greets,
Ace

wysota
10th August 2006, 00:34
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...