Project

General

Profile

Problems Changing Text in TreeView

Added by Mirko Stocker over 14 years ago

Hello!

I'm currently evaluating Wt; and I'm quite impressed by how easy and Qt-like it works. But I've now hit a wall and need some help. When I update the model underlying a TreeView, the old text of the WStandardItem does not get replaced but the new text is appended. The following is an example of what I do; when pressing the save button, I'd expect that the selected item's text is replaced with "5", but what I get instead is "15" or "25" respectively.

class TestApp : public WApplication {
public:
  TestApp( const WEnvironment& env ) :
    WApplication( env ) {

    WPushButton* button = new WPushButton( "save", root() );
    button->clicked().connect( SLOT( this, TestApp::save ) );

    model_ = new Wt::WStandardItemModel( root() );

    model_->appendRow( new WStandardItem( "1" ) );
    model_->appendRow( new WStandardItem( "2" ) );

    treeView_ = new WTreeView( root() );
    treeView_->setModel( model_ );
    treeView_->setSelectionMode( SingleSelection );
  }

  void save() {
    WModelIndex i = *treeView_->selectedIndexes().begin();
    model_->itemFromIndex( i )->setText( WString( "5" ) );
  }

  WTreeView *treeView_;
  WStandardItemModel *model_;
};

Thanks in advance for any help!


Replies (5)

RE: Problems Changing Text in TreeView - Added by Mirko Stocker over 14 years ago

I've just discovered that executing the following two statements after the setText fixes the display:

model_->layoutAboutToBeChanged().emit();
model_->layoutChanged().emit();

RE: Problems Changing Text in TreeView - Added by Koen Deforche over 14 years ago

Hey,

You indeed hit a bug, which occurs when changing an item in the first column in a single column model.

The latest git version fixes this. Your workaround will work, but will always rerender the entire treeview.

Regards,

koen

RE: Problems Changing Text in TreeView - Added by Mirko Stocker over 14 years ago

Hi Koen

The behavior has changed with your latest commit, but the bug doesn't seem to be fixed for me. Using the application mentioned above, the '5' still doesn't replace the existing text but creates a row that is twice the original height with '1' and '5' on separate lines (see the attached screenshot; it shows the problem in Chromium, but it behaves the same in Firefox).

Regards,

Mirko

RE: Problems Changing Text in TreeView - Added by Koen Deforche over 14 years ago

Hey Mirko,

It did work at one time and then I messed it up again... I corrected it now in git.

Regards,

koen

RE: Problems Changing Text in TreeView - Added by Mirko Stocker over 14 years ago

Yes, now it works :-)

Thank you very much

Mirko

    (1-5/5)