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 8254689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:16:42+00:00 2026-06-08T01:16:42+00:00

I have QTreeWidget in a widget in Maya (A 3D computer graphics application). The

  • 0

I have QTreeWidget in a widget in Maya (A 3D computer graphics application). The problem is, my widget is not only blocking the native CTRL+A hotkey, it is selecting everything in my tree. How can I let this hot key bubble up to the parent application?

I am already using event filters for a lot of custom key handling, but it seems like the tree wants to handle this one for me. I like the arrow key functionality, so i don’t want to disable all key bindings, but if I have to, I will… if I knew how

Cheers,

P.S. Something similar was asked here but the answer ignores the question:
qt: I would like to disable the key bindings automatically set for a QTreeView


Here is A solution in Python for a QTreeWidget.

I can’t decided if this is the dirtiest thing I have ever done with Python or just a nifty Python version of an extension method! (It feels like the former.)

The problem is, I don’t actually have the QTreeView class. It was added in designer with the name “tree”, so I literally overrode the method then call the base functionality from my method…

def __init__ #...snip...
    self.tree.keyPressEvent = self.onKeyPressEvent # Replace with my method


def onKeyPressEvent(self, event):
    if event.key() == Qt.Key_A and event.modifiers() == Qt.ControlModifier:
        event.ignore()  # Allows fall-through to the parent
        return

    QtGui.QTreeView.keyPressEvent(self.tree, event)  # All other behaviors handled

…so that is just too dirty for me. I knew there had to be a solution to this common situation (not having a subclass). I am already using event filters, so I tried it and it worked. The key was knowing where the event was being handled and using both event.ignore() as well as returning True to allow the event to bubble up and block the KeyPressEvent for CTRL+A.

def eventFilter(self, obj, event):
    # Filter out all non-KeyPress events
    if not event.type() == QEvent.KeyPress:
        return False

    if event.key() == Qt.Key_A and event.modifiers() == Qt.ControlModifier:
        event.ignore()  # Allows fall-through to the parent
        return True     # Block the tree's KeyPressEvent

    return False        # Do nothing
  • 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-06-08T01:16:44+00:00Added an answer on June 8, 2026 at 1:16 am

    Reimplement the keyPressEvent, and when CTRL+A is pressed, ignore the event.

    The code should then look similar to this:

    MyTreeView::keyPressEvent(QKeyEvent *e)
    {
        if(e->key() == Qt::Key_A && e->modifiers() == Qt::ControlModifier)
        {
            e->ignore();
            QWidget::keyPressEvent(e); // Not sure about this. Please try and report!
        }
        else
            QTreeView::keyPressEvent(e);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of QTreeWidgetItems (with children) in a QTreeWidget. I do not
I have a Qt application that contains a QTreeWidget. I want to replace one
I have a QTreeWidget which needs to be populated with a large sum of
I have to populate a QTreeWidget with items (or children of items) that may
Is it possible to have individual indentation of items in a QTreeWidget? In specific,
I use a QTreeWidget to display multicolumn items, and I want to have a
I can't seem to get any mouse clicks in a QTreeWidget. I have tried...
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have two columns in a QTreeWidget , one column represents a list of
I have an application written with pyside where a user can load an image,

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.