Results 1 to 3 of 3

Thread: QDataWidgetMapper with QTreeView

  1. #1
    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    50
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QDataWidgetMapper with QTreeView

    Hi All

    On a QWidget I've displayed a QTreeView and QTabWidget. They both have the same QAbstractItemModel as source model and the idea is to view the treestructure in the treeview but let the user modify the individual items in the QTabWidget where the items are also shown. Basically exactly the same as in C++ GUI Programming with Qt 4, the staff manager example (relevant section starts p.324).

    Everything works according to plan but QDataWidgetMapper will only display items from the QTreeView column 0 so only top level treeitems are displayed in the QDataWidgetMapper.

    I initiate the QDataWidgetMapper with;
    Qt Code:
    1. mapper->setModel(mytreemodel);
    2. mapper->setRootIndex(myTreeView->rootIndex() );
    3.  
    4. //connect model to mapper
    5. connect(myTreeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
    6. mapper, SLOT(setCurrentModelIndex(QModelIndex)));
    To copy to clipboard, switch view to plain text mode 

    With this setup only top nodes will be displayed! I've tried with

    Qt Code:
    1. connect(myTreeView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
    2. mapper, SLOT(setCurrentModelIndex(QModelIndex)));
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. connect(myTreeView->selectionModel(), SIGNAL(currentColumnChanged(QModelIndex,QModelIndex)),
    2. mapper, SLOT(setCurrentModelIndex(QModelIndex)));
    To copy to clipboard, switch view to plain text mode 

    and both of them at the same time but no luck.

    Any idea out there how I can get the QDataWidgetMapper to change with the QTreeView selection change?

    Thanks

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

    Default Re: QDataWidgetMapper with QTreeView

    You have to adjust the root index of the data widget mapper.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Nightfox (1st September 2009)

  4. #3
    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    50
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDataWidgetMapper with QTreeView

    Hi wysota

    Thanks for your reply. I changed the slot from the connect above with a custom slot which is called each time selected item changes in the treeview. The new code is

    Qt Code:
    1. connect(myTreeView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
    2. this, SLOT(rowcolchange(QModelIndex) ));
    3.  
    4. void myQWidget::rowcolchange(const QModelIndex & index )
    5. {
    6. mapper->setRootIndex(index.parent());
    7. mapper->setCurrentModelIndex(index);
    8. }
    To copy to clipboard, switch view to plain text mode 

    Now it works - thanks again!

Similar Threads

  1. QTreeView repaint
    By graeme in forum Qt Programming
    Replies: 17
    Last Post: 13th March 2012, 13:27
  2. QDirModel and QTreeView cut and paste
    By Micawber in forum Qt Programming
    Replies: 4
    Last Post: 28th May 2008, 20:16
  3. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 21:22
  4. QTreeView: Holding a line on screen
    By gri in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 11:42
  5. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 14:24

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.