i tried and menu did worked.
I need some advice on how to proceed further.
As we discussed in thread http://www.qtcentre.org/forum/f-newb...ases-3928.html
, i have a large canvas , over this i have many canvs elements and some other smallcanvas. Now i want this context menu to be specific to element on which it is clicked.I mean i have diffrent function corresponding to diffrent element. These operation includes , changing elements shape and displayig information(selective) about that element.
if i do this, this is generating a general context menu, orignating same at each place irrespective of click where it happenend or i can get position from QContextMenuEvent class.
...
connect(abc,SIGNAL(triggered()),this,SLOT(ABC()));
...
void ABC()
{
QMessageBox::information(this,tr
("Hello"),tr
("Sample Context Menu Acion"));
}
...
{
mn.addAction(abc);
mn.exec(event->globalPos());
}
...
abc=new QAction(tr("hello"),this);
connect(abc,SIGNAL(triggered()),this,SLOT(ABC()));
...
void ABC()
{
QMessageBox::information(this,tr("Hello"),tr("Sample Context Menu Acion"));
}
...
void contextMenuEvent(QContextMenuEvent *event)
{
QMenu mn(this);
mn.addAction(abc);
mn.exec(event->globalPos());
}
To copy to clipboard, switch view to plain text mode
same here
{
Q3CanvasItemList il = canvas()->collisions( e->pos() );
if(e->button()==Qt::LeftButton)
{
for( Q3CanvasItemList::Iterator it=il.begin(); it!=il.end(); ++it ) {
if( (*it)->rtti() != Q3CanvasText::RTTI )
{
dragging = (*it);
xoffset = (int)(e->x() - dragging->x());
yoffset = (int)(e->y() - dragging->y());
return;
}
}
}
else if(e->button()==Qt::RightButton)
{
for( Q3CanvasItemList::Iterator it=il.begin(); it!=il.end(); ++it ) {
if( (*it)->rtti() != Q3CanvasText::RTTI )
{
if( (*it)->rtti() == Q3CanvasRectangle::RTTI)
{
QMessageBox::information(this,tr
("Hello"),tr
("Sample Context Menu Acion on rectangle"));
//[COLOR="Red"]can generate a specific menu here but how will pass this canvas element to that action for operations over that[/COLOR]
}
}
}
}
}
void contentsMousePressEvent( QMouseEvent *e )
{
Q3CanvasItemList il = canvas()->collisions( e->pos() );
if(e->button()==Qt::LeftButton)
{
for( Q3CanvasItemList::Iterator it=il.begin(); it!=il.end(); ++it ) {
if( (*it)->rtti() != Q3CanvasText::RTTI )
{
dragging = (*it);
xoffset = (int)(e->x() - dragging->x());
yoffset = (int)(e->y() - dragging->y());
return;
}
}
}
else if(e->button()==Qt::RightButton)
{
for( Q3CanvasItemList::Iterator it=il.begin(); it!=il.end(); ++it ) {
if( (*it)->rtti() != Q3CanvasText::RTTI )
{
if( (*it)->rtti() == Q3CanvasRectangle::RTTI)
{
QMessageBox::information(this,tr("Hello"),tr("Sample Context Menu Acion on rectangle"));
//[COLOR="Red"]can generate a specific menu here but how will pass this canvas element to that action for operations over that[/COLOR]
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
i know on which element i clicked but how i can pass this information( on which object on canvas or window i clicked ) to actions on context menu. Why i need context menu is since i have 5-6 oprns. User will select between them.
all advices are welcome in this regard as i am getting very raw ideas(working on such task for first time).
Bookmarks