Results 1 to 4 of 4

Thread: QMenu's QAction works with QShortcut, not with button

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: QMenu's QAction works with QShortcut, not with button

    You should post the rest of the code.

    By the way, how is it that QKeySequence::Open maps to Ctrl+C for you, and not Ctrl+O per the docs?

  2. #2
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMenu's QAction works with QShortcut, not with button

    Oh, wow. I meant Ctrl+O, of course. Don't know what happened there.

    Here's the rest of the constructor. I can't post the remainder of the code because, well, its a few thousand lines long. The class Canvas inherits from QWidget and sf::RenderWindow, from the SFML Graphics library.

    Qt Code:
    1. Canvas::Canvas(const QPoint& Position, const QSize& Size,QWidget* Parent) :
    2. QSFMLCanvas(Parent, Position, Size),
    3. MenuBar(this)
    4. {
    5. setMouseTracking(true);
    6. setAttribute(Qt::WA_DeleteOnClose);
    7. points.reserve(3000);
    8.  
    9. EqualizeSize=0;
    10. PointsVisible=true;
    11.  
    12. QMenu* menu = MenuBar.addMenu("File");
    13. menu->addAction("&Open",this,SLOT(OpenFile()),QKeySequence::Open);
    14. menu->addAction("&Save",this,SLOT(SaveFile()),QKeySequence::Save);
    15. menu->addAction("&Quit",QCoreApplication::instance(),SLOT(quit()),QKeySequence::Quit);
    16. menu = MenuBar.addMenu("Edit");
    17. menu->setEnabled(false);
    18. connect(this,SIGNAL(FileLoaded(bool)),menu,SLOT(setEnabled(bool)));
    19. QAction* action = menu->addAction("&Fault Properties",this,SLOT(FaultPropertiesDlg()),QString("Ctrl+F"));
    20. action->setEnabled(false);
    21. connect(this,SIGNAL(FileLoaded(bool)),action,SLOT(setEnabled(bool)));
    22. action = menu->addAction("&Equalize Fault Segments",this,SLOT(EqualizeDlg()),QString("Ctrl+E"));
    23. action->setEnabled(false);
    24. connect(this,SIGNAL(FileLoaded(bool)),action,SLOT(setEnabled(bool)));
    25. menu->addSeparator();
    26. action = menu->addAction("&Define Seafloor",this,SLOT(SeafloorDlg()),QString("Ctrl+D"));
    27. action->setEnabled(false);
    28. connect(this,SIGNAL(FileLoaded(bool)),action,SLOT(setEnabled(bool)));
    29. action = menu->addAction("&New Horizon",this,SLOT(NewHorizonDlg()),QString("Ctrl+N"));
    30. action->setEnabled(false);
    31. connect(this,SIGNAL(SeaFloorDefined(bool)),action,SLOT(setEnabled(bool)));
    32. action = menu->addAction("&Horizon Properties",this,SLOT(HorizonPropertiesDlg()),QString("Ctrl+H"));
    33. action->setEnabled(false);
    34. connect(this,SIGNAL(SeaFloorDefined(bool)),action,SLOT(setEnabled(bool)));
    35. menu = MenuBar.addMenu("View");
    36. menu->setEnabled(false);
    37. connect(this,SIGNAL(FileLoaded(bool)),menu,SLOT(setEnabled(bool)));
    38. action = menu->addAction("&Global View",this,SLOT(ChangeView_Key()),QString("Ctrl+G"));
    39. action->setEnabled(false);
    40. connect(this,SIGNAL(FileLoaded(bool)),action,SLOT(setEnabled(bool)));
    41. action = menu->addAction("&Show Sealevel",this,SLOT(ViewSealevel()));
    42. action->setEnabled(false);
    43. action->setCheckable(true);
    44. action->setChecked(true);
    45. connect(this,SIGNAL(FileLoaded(bool)),action,SLOT(setEnabled(bool)));
    46. connect(this,SIGNAL(ViewingSealevel(bool)),action,SLOT(setChecked(bool)));
    47. action = menu->addAction("Show &Points",this,SLOT(ViewPoints()));
    48. action->setEnabled(false);
    49. action->setCheckable(true);
    50. action->setChecked(true);
    51. connect(this,SIGNAL(FileLoaded(bool)),action,SLOT(setEnabled(bool)));
    52. connect(this,SIGNAL(ViewingPoints(bool)),action,SLOT(setChecked(bool)));
    53. menu = MenuBar.addMenu("Analyze");
    54. menu->setEnabled(false);
    55. connect(this,SIGNAL(SeaFloorDefined(bool)),menu,SLOT(setEnabled(bool)));
    56. action = menu->addAction("Estimate Maximum PPI",this,SLOT(PPIDlg()),QString("Ctrl+A"));
    57. action->setEnabled(false);
    58. connect(this,SIGNAL(SeaFloorDefined(bool)),action,SLOT(setEnabled(bool)));
    59. action = menu->addAction("View Geostatic Ratio",this,SLOT(ViewRatio()),QString("Ctrl+R"));
    60. action->setEnabled(false);
    61. action->setCheckable(true);
    62. connect(this,SIGNAL(RatioCalculated(bool)),action,SLOT(setEnabled(bool)));
    63. connect(this,SIGNAL(ViewingRatio(bool)),action,SLOT(setChecked(bool)));
    64. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QMenu does not show icons from QAction
    By eumel1990 in forum Newbie
    Replies: 5
    Last Post: 10th September 2011, 10:57
  2. Can't disable a QAction in QMenu
    By punkypogo in forum Qt Programming
    Replies: 3
    Last Post: 10th August 2010, 14:07
  3. how to add QMenu or QAction inside QDesigner
    By eric_vi in forum Qt Tools
    Replies: 1
    Last Post: 2nd August 2009, 16:48
  4. QAction text color (QMenu)
    By StefanK in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2009, 15:14
  5. QPushButton QMenu QAction
    By hgedek in forum Newbie
    Replies: 2
    Last Post: 1st November 2007, 12:29

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.