Actions and focus

  • We have an application with several documents in a tab pane in the main area. We have cut/paste and such defined on the menu and we would like only the focused document to receive these events.

    I was mistakenly under the impression that all documents would register with the actions and then QT would take care of not sending action signals to documents that do not have (and aren't visible) but that doesn't appear to be the case; we are getting actions that apply to multiple documents which makes sense physically.

    Do you need to manage the set of actions that can only apply to a focused document ourselves (meaning register/unregister on focus/lostFocus respectively) or is there a mechanism in QT to conditionally register an action where the condition would be:

    if (hasFocus) then do action else ignore?


  • I am assuming that you are using QTextEdit or a derived class for your documents. If so, then you could reimplement insertFromMimeData method with something like:

    @ void ClassName::insertFromMimeData(QMimeData *source) {
    if(this->hasEditFocus()) QTextEdit::insertFromMimeData(source);
    else return;

    Also QT = Quick Time. You are using Qt

  • That doesn't seem to address the entire post. That specifically addresses paste, but I want a general mechanism for the set of actions that should only apply to the focused document.

    We aren't using only QTextEdit, we are using a multitude of document types so in any case your fix is far, far too specific.

    Thanks for the QT vs Qt correction, however.


Log in to reply