PDA

View Full Version : using the example of simple tree model



krishna.bv
22nd December 2006, 11:56
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.

ggrinder
22nd December 2006, 12:28
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:


// let tv be a pointer to your treeview
tv->setContextMenuPolicy( Qt::CustomContextMenu );

This causes the tree view to emit the "customContextMenuRequested( const QPoint& )" signal.

The slot for the signal to connect to may look like:


void CMyClass::ProvideContexMenu( const QPoint& pnt ){

QModelIndex idx = tv->indexAt( pnt );
if( idx.isValid( ) )
MyContextMenu->popup( tv->mapToGlobal( pnt ) );
}
Usually you need to remember the index, to apply the user selected action to it.