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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:11:22+00:00 2026-06-02T08:11:22+00:00

I have this code: bool MainWindow::eventFilter(QObject *obj, QEvent *event) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);

  • 0

I have this code:

bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
    QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);

    if (event->type() == QEvent::KeyPress)
    {
        if (keyEvent->key() == Qt::Key_Tab)
            // do something
    }
}

Now, I am typing in a QTextEdit. So say I hit the tab key. Then a tab will occur in the QTextEdit. But what if I want to prevent that from happening? For an analogy, if you are familiar with emacs: when in the right environment (say c++ mode), you can hit tab, and the line jumps to the right position (indenting). After hitting tab again, nothing happens. This is because the line of code is in the right position.

Anybody here knows how to do this? I guess I can let the tab event to be displayed in QTextEdit, and then delete previous char (or whatever it is defined as).

  • 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-02T08:11:24+00:00Added an answer on June 2, 2026 at 8:11 am

    Using the return value of your event filter function will let you control which events your QTextEdit receives (if you really don’t want to just subclass it):

    if (keyEvent->key() == Qt::Key_Tab)
        return true;
    

    Returning true indicates that the event should be filtered.

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

Sidebar

Related Questions

I have this code in base class protected virtual bool HasAnyStuff<TObject>(TObject obj) where TObject:class
Lets say we have this code: bool KeepGoing = true; DataInThread = new Thread(new
I have code like this: public bool Set(IEnumerable<WhiteForest.Common.Entities.Projections.RequestProjection> requests) { var documentSession = _documentStore.OpenSession();
I have this code here, which is intended to allow any type of arguments:
Right now, I have this code: bool isAnyTrue() { for(std::list< boost::shared_ptr<Foo> >::iterator i =
I have this code I currently use to validate emails: return (bool) preg_match('/^([a-z0-9\+\_\-\.]+)@([a-z0-9\+\_\-\.]{2,})(\.[a-z]{2,4})$/i', $arg0);
I have this code typedef struct { const char* fooString; const bool fooBool; }fooStruct;
i have this code to create a local windows user public static bool CreateLocalWindowsAccount(string
I have this code for doing an ajax request to a webservice: var MyCode
I have this code: $(div[id^='intCell']).mouseover(function() { $(this).css({ border:,1px solid #ff097c}); }).mouseout(function() { $(this).css({border:,1px solid

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.