PDA

View Full Version : QWT right click window.. (Context Menu)



maveric
22nd May 2008, 11:54
hi all,

i am new to this world of qt...
I need to create an application where on my window if i take right click i need to get a context menu.. with some actions like cut, copy, paste, select all, etc....



menu = new QMenu(this);
menu->addAction("Cut");
menu->addAction("Copy");
menu->addAction("Paste");
menu->addSeparator();
menu->addAction("Select All");
......(list goes to 10)....

connect(menu, SIGNAL(triggered(QAction*)), SLOT(triggeredSlot(QAction*)));


i am getting many errors... with my application...
can any one tell me what to do .... please.....

jacek
22nd May 2008, 15:03
Could you post the first error message?

maveric
23rd May 2008, 06:04
Hi,

first of all thanks for replying me...
well to start
I have kept this context menu for plotting graph..
what i need is when my plotting is running i need to adjust my values at run time...
This is the code which i tried for context menu..



menu = new QMenu(this);
menu->addAction("New Plot");
menu->addAction("Refresh Plot");
menu->addSeparator();
menu->addAction("Reset Plot");
menu->addAction("Change Scalling Speed");
menu->addSeparator();
-------
-------
-------
menu->addSeparator();
menu->addAction("Exit");

connect(menu, SIGNAL(triggered(QAction*)), SLOT(triggeredSlot(QAction*)));



1>------ Build started: Project: PlottingGraph, Configuration: Release Win32 ------
1>Compiling...
moc_plottinggraph.cpp
plottinggraph.cpp
.\plottinggraph.cpp(58) : error C2065: 'menu' : undeclared identifier
.\plottinggraph.cpp(59) : error C2227: left of '->addAction' must point to class/struct/union/generic type
type is ''unknown-type''
.\plottinggraph.cpp(60) : error C2227: left of '->addAction' must point to class/struct/union/generic type
type is ''unknown-type''
.\plottinggraph.cpp(61) : error C2227: left of '->addAction' must point to class/struct/union/generic type
type is ''unknown-type''
.\plottinggraph.cpp(62) : error C2227: left of '->addSeparator' must point to class/struct/union/generic type
type is ''unknown-type''
.\plottinggraph.cpp(66) : error C2227: left of '->addSeparator' must point to class/struct/union/generic type
type is ''unknown-type''
.\plottinggraph.cpp(67) : error C2227: left of '->addAction' must point to class/struct/union/generic type
type is ''unknown-type''
main.cpp
Generating Code...

PlottingGraph - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




please help me..
thanx in advance..

aamer4yu
23rd May 2008, 06:53
Is menu a member variable of your class ??

I guess u have not declared it :(

kaustav98255
25th May 2008, 08:07
Hi,
I have done something similar in python, I would assume the situation to be no different in C++. Here it goes:

you can put the signals & slot connections in your class contructor for the plot:
self.connect(self,
SIGNAL('plotMouseMoved(const QMouseEvent&)'),
self.onMouseMoved)
self.connect(self,
SIGNAL('plotMouseReleased(const QMouseEvent&)'),
self.onMouseReleased)
# end of __init__() - nothing more is required here.

def onMouseMoved(self, e):
pass

def on MouseReleased(self,e):
# bind popUp menu event to popUp menu
popupEvent = QContextMenuEvent(QContextMenuEvent.Mouse,e.pos(), False)

if Qt.RightButton == e.button(): # right-mouse button clicked
#you can set you own condition to accept() the pop-Up event and then can create the pop-up menu according to your needs.
popupEvent.accept() # accept the pop-Up event - show the pop-Up menu

#create the menu here

For the C++ code,
i am not very sure what is going wrong.

Thanks
Kaustav.