Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, March 2007
Tree not updated after inserted nodes..


Message 1 in thread

Hi,

How can I notify the QTreeWidget if I insert a new node after the widget 
has been shown ? For instance if I add a node with something like this:

tree.topLevelItem(0).insertChild(0, newItem);

is there some signal or someting to call to notify the widget that a new 
node is inserted ?.   If a doubleclick the node in the gui the node 
suddenly becomes visible

-=Børge


Message 2 in thread

Børge Austvold wrote:
> Hi,
> 
> How can I notify the QTreeWidget if I insert a new node after the widget 
> has been shown ? For instance if I add a node with something like this:
> 
> tree.topLevelItem(0).insertChild(0, newItem);
> 
> is there some signal or someting to call to notify the widget that a new 
> node is inserted ?.   If a doubleclick the node in the gui the node 
> suddenly becomes visible

Hi Børge,

This is a bug in the QTreeView and because of inheritance, QTreeWidget 
inherits that bug. I've notified the itemviews team here so hopefully 
the bug will be fixed soon.

You can work around this bug by doing a call to layoutChanged() after 
you inserted a child like this:

             QTreeWidgetItem item = new QTreeWidgetItem();
             item.setText(0, "Child");
             root.insertChild(0, item);
             root.setText(0, "Root with child");

             model().layoutChanged.emit();

-
Gunnar

import com.trolltech.qt.gui.*;
import com.trolltech.qt.gui.*;
import com.trolltech.qt.*;
import com.trolltech.qt.core.*;

public class TreeWidget extends QTreeWidget {

    private QTreeWidgetItem root;
    private int id = -1;

    public TreeWidget() {
        root = new QTreeWidgetItem();
        root.setText(0, "Root");
        addTopLevelItem(root);

        setColumnCount(1);

        id = startTimer(2000);
    }

    protected void timerEvent(QTimerEvent e) {
        if (id == e.timerId()) {
            QTreeWidgetItem item = new QTreeWidgetItem();
            item.setText(0, "Child");
            root.insertChild(0, item);
            root.setText(0, "Root with child");

            model().layoutChanged.emit();
        } else
            super.timerEvent(e);
    }

    public static void main(String args[]) {
        QApplication.initialize(args);

        TreeWidget w = new TreeWidget();
        w.show();

        QApplication.exec();
    }
}