Results 1 to 5 of 5

Thread: QWT right click window.. (Context Menu)

  1. #1
    Join Date
    May 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Question QWT right click window.. (Context Menu)

    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....

    Qt Code:
    1. menu = new QMenu(this);
    2. menu->addAction("Cut");
    3. menu->addAction("Copy");
    4. menu->addAction("Paste");
    5. menu->addSeparator();
    6. menu->addAction("Select All");
    7. ......(list goes to 10)....
    8.  
    9. connect(menu, SIGNAL(triggered(QAction*)), SLOT(triggeredSlot(QAction*)));
    To copy to clipboard, switch view to plain text mode 

    i am getting many errors... with my application...
    can any one tell me what to do .... please.....
    Last edited by maveric; 22nd May 2008 at 11:56. Reason: spelling error

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWT right click window.. (Context Menu)

    Could you post the first error message?

  3. #3
    Join Date
    May 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QWT right click window.. (Context Menu)

    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..
    Qt Code:
    1. menu = new QMenu(this);
    2. menu->addAction("New Plot");
    3. menu->addAction("Refresh Plot");
    4. menu->addSeparator();
    5. menu->addAction("Reset Plot");
    6. menu->addAction("Change Scalling Speed");
    7. menu->addSeparator();
    8. -------
    9. -------
    10. -------
    11. menu->addSeparator();
    12. menu->addAction("Exit");
    13.  
    14. connect(menu, SIGNAL(triggered(QAction*)), SLOT(triggeredSlot(QAction*)));
    To copy to clipboard, switch view to plain text mode 

    [errors]
    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 ==========

    [/errors]


    please help me..
    thanx in advance..

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWT right click window.. (Context Menu)

    Is menu a member variable of your class ??

    I guess u have not declared it

  5. #5
    Join Date
    Apr 2008
    Location
    Bangalore, India
    Posts
    7
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QWT right click window.. (Context Menu)

    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.

Similar Threads

  1. Double click resize window disable
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2008, 11:35
  2. Set a window as child at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2007, 09:30
  3. close window when click on a label
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 07:35
  4. QTextBrowser - click on link - closes window
    By bruccutler in forum Newbie
    Replies: 2
    Last Post: 19th June 2007, 20:39
  5. Replies: 1
    Last Post: 9th February 2007, 09:41

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.