Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What is event->accept means in contextMenuEvent
Qt 6.11 is out! See what's new in the release blog

What is event->accept means in contextMenuEvent

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 834 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    class myTextEdit: public QTextEdit

    void myTextEdit:contextMenuEvent(QContextMenuEvent event) {
    QMenu * menu = createStandardContextMenu();
    QAction clearAction = new IN_CURRENT_POOL QAction("Clear",this);
    clearAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
    connect(clearAction,SIGNAL(triggered()),this,SLOT(clear()));
    menu->addSeparator();
    menu->addAction(clearAction);
    menu->exec(event->globalPos());
    delete menu;
    event->accept();
    }

    What will happend if I do not put event->accept(); in this case and From the documenntation , I could not make it what does event->accept(); do in above code .

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      From the documentation (http://doc.qt.io/qt-5/qevent.html#accept):

      void QEvent::accept()
      
      Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
      
      Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget.
      

      If you call accept then the event is not propagated to the parent of the widget. If you reject the event then it is propagated to the parent widget which then can do what ever it does with such events.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved