Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 645595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:31:13+00:00 2026-05-13T21:31:13+00:00

Greetings, for one of my applications I’m trying to implement an Edit menu. This

  • 0

Greetings,

for one of my applications I’m trying to implement an “Edit” menu. This menu usually has the standard-entries Undo, Cut, Copy and Paste.

This menu is not there by default, and users seem to expect it especially on Mac OS X.

Is there a an easier way of implementing this, without doing so in every widget manually? Since most widgets have the copy/paste/undo mechanism already implemented via shortcuts, I’d like to provide a few simple menu actions that call them as well.

The actions should call whatever widget has the focus first, then they should pass the events upwards the object chain, I guess.

I’m using Qt 4.6 on Windows, Linux and Mac OS X.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:31:13+00:00Added an answer on May 13, 2026 at 9:31 pm

    It’s easy enough to accomplish half of the necessary functionality. Just create the Edit menu, along with the necessary QActions (copy/paste/undo/etc.) in your main window class and connect them to slots. In the slots, emulate the correct key press and release events (e.g. Ctrl+C for Copy) and send them to the currently focused widget. In code, something like this:

    MainWindow::MainWindow(...)
    {
        ...
        connect( actionCopy, SIGNAL( triggered()), SLOT( copy()));
        ...
    }
    ...
    void MainWindow::copy()
    {
        QWidget* focused = QApplication::focusWidget();
        if( focused != 0 )
        {
            QApplication::postEvent( focused,
                                     new QKeyEvent( QEvent::KeyPress,
                                                    Qt::Key_C,
                                                    Qt::ControlModifier ));
            QApplication::postEvent( focused,
                                     new QKeyEvent( QEvent::KeyRelease,
                                                    Qt::Key_C,
                                                    Qt::ControlModifier ));
    }
    

    Of course, this is quite a hack. You need to modify the code for each target platform, changing the keyboard shortcuts to the correct ones, and it might happen that a widget that receives focus does something quiet unexpected with Ctrl+C. The worst downside in this method, in my opinion, is that you cannot properly control the enabled state of the Edit menu items. It is not possible to query from a generic widget whether a copy or paste operation would be possible or not.

    I am unable to find a real solution to this problem – and would be surprised to find out that one exists – as the copy/paste functionality is generally hidden inside the class’ code and not exposed through any standard set of signals/slots. After tonight’s experiments with the functionality, I have decided to just forget having an Edit menu from my application and expect the users to know the keyboard shortcuts, or use the context sensitive menus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I am trying to perform a copy from one vector (vec1) to another
SO buddies, greetings. I have some password requirements I need to implement and one
Greetings everyone. Can any one has a working example for the CoreTelephony framework? I
Greetings! I am trying to build an application which has a flex front-end and
Greetings, I'm trying to create a pagination panel for one of my lists and
Greetings, I would like to ask if creating Singleton to have only one active
Greetings everyone and thank you for checking out my post. I am trying to
Greetings, I am trying to learn pointers in C, I simply want my addtwo
Greetings, Trying to sort through the best way to provide access to my Entity
Greetings, I'm trying to select item from asp.net list box then assign it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.