Results 1 to 2 of 2

Thread: using the example of simple tree model

  1. #1
    Join Date
    Dec 2006
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default using the example of simple tree model

    Hi, i really feel happy in receiving immediate response for my query.
    i need to develop a tree model for my project. i used the simple tree model from examples.
    but i need to do some modifications for it to fit it into my project.
    1. I need to get popup menu for a right click on a row with actions.
    2. I need to update the treeItem / model with data from a data base.

    can any one please help me with the above problems.

    thanks in advance,

    regards,
    krishna.

  2. #2
    Join Date
    Dec 2006
    Posts
    9
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: using the example of simple tree model

    I can only help you with the first problem:

    You can advice the QTreeView to emit a signal when a context menu event occurs and handle it in another QObject derived class, e.g. the parent widget of the tree view.

    To accomplish this you need to change the context menu policy of the view:
    Qt Code:
    1. // let tv be a pointer to your treeview
    2. tv->setContextMenuPolicy( Qt::CustomContextMenu );
    To copy to clipboard, switch view to plain text mode 
    This causes the tree view to emit the "customContextMenuRequested( const QPoint& )" signal.

    The slot for the signal to connect to may look like:
    Qt Code:
    1. void CMyClass::ProvideContexMenu( const QPoint& pnt ){
    2.  
    3. QModelIndex idx = tv->indexAt( pnt );
    4. if( idx.isValid( ) )
    5. MyContextMenu->popup( tv->mapToGlobal( pnt ) );
    6. }
    To copy to clipboard, switch view to plain text mode 
    Usually you need to remember the index, to apply the user selected action to it.

Similar Threads

  1. Sharing Selections between Model and ProxyModel
    By mentat in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2010, 18:31
  2. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 21:17
  3. traversing tree using mouse clicks
    By krishna.bv in forum Qt Programming
    Replies: 3
    Last Post: 22nd December 2006, 10:15
  4. Model sorting vs. selection
    By VlJE in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 17:46
  5. data, model and tree view
    By larry104 in forum Qt Programming
    Replies: 17
    Last Post: 3rd July 2006, 15:43

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.