Results 1 to 7 of 7

Thread: auto checkox fresh in qtreeview problem.

  1. #1
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default auto checkox fresh in qtreeview problem.

    i have a custom model, and want to achieve the effect in attachment pic.
    now i can react on the setdata method in model,like below:
    //-------------------------------------------------
    bool TorgTreeModel::setData( const QModelIndex & index, const QVariant & value, int role /*= Qt::EditRole */ )
    {

    if (!index.isValid())
    return true;


    TorgTreeItem *item = static_cast<TorgTreeItem*>(index.internalPointer() );

    if (role == Qt::CheckStateRole && index.column() ==0)
    {
    item->setCheckState( static_cast<Qt::CheckState>(value.toUInt()));
    // emit dataChanged(createIndex(0,0,m_root_item),
    // createIndex(m_root_item->childCount()-1,0,m_root_item));
    return true;
    }

    return QAbstractItemModel::setData(index,value,role);
    }

    i can change all checkstate of the model data for the right value, but i can't tell qtreeview to refresh the new data.
    i use beginresetmodel/endresetmodel ,it does refresh,but qtreeview not keep the display layout.
    now with my code, when i switch to other program and back, qtreeview display ok, but this is not the solution.

    is there any other convenient way to tell the qtreeview update the display?
    or there is other way to achieve the same effect?
    thanks in advance!
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: auto checkox fresh in qtreeview problem.

    Didnt emit dataChanged work for you ?

    Also try calling view->update();

  3. #3
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: auto checkox fresh in qtreeview problem.

    solved by emit dataChanged signal for every model item that change check state.

  4. #4
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: auto checkox fresh in qtreeview problem.

    oh,it does not solved, there must be something wrong, though i have emit every datachange signal for every change item, qtreeview doesn't refresh well.
    may be i don't have write the right code, but it seems beyond my brain now.
    i have attach a test demo.
    Attached Files Attached Files

  5. #5
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: auto checkox fresh in qtreeview problem.

    my compile info: qt 4.6.2 on win xp sp3 with vs2008.
    it doesn't use any windows special, it should compile everywhere that qt supported.

  6. #6
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: auto checkox fresh in qtreeview problem.

    when compile with qt 4.7 beta1, the same effect as 4.6.2.

  7. #7
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: auto checkox fresh in qtreeview problem.

    seems solved by rewrite method
    //-------------------------------------------------
    void TorgTreeModel::emitDataChanged( TorgTreeItem* item )
    {
    TorgTreeItem* parent_item = getOrgItem(item->parent_org_id);
    emit dataChanged(createIndex(item->row(),0,parent_item),createIndex(item->row(),1,parent_item));

    qDebug() << "datachange" << item->org_full_name;
    }

Similar Threads

  1. Replies: 3
    Last Post: 12th February 2010, 10:10
  2. A very fresh new Qt programmer =)
    By ZikO in forum Installation and Deployment
    Replies: 5
    Last Post: 4th December 2009, 15:24
  3. compiling hello world after fresh install fails
    By kvesi in forum Installation and Deployment
    Replies: 3
    Last Post: 19th September 2008, 13:55
  4. Program not compiling on Fresh install of Leopard
    By dvmorris in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 10:22
  5. I'm a fresh,how this problem could be resolved?
    By defyer in forum Qt Programming
    Replies: 6
    Last Post: 16th July 2007, 08:04

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.