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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:25:40+00:00 2026-06-04T00:25:40+00:00

I have a QLineEdit, on which I have set a QRegExpValidator, that allows the

  • 0

I have a QLineEdit, on which I have set a QRegExpValidator, that allows the user to input only one whitespace between words.
Now I want that whenever the user tries to enter more than one whitespaces, the tooltip of the QLineEdit should show up, but I’m not getting any method to implement it.

Thanx 🙂

  • 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-04T00:25:42+00:00Added an answer on June 4, 2026 at 12:25 am

    It seems there is no direct method to perform what you want. One way to do above is to handle QLineEdit‘s textChanged() signal. Then you can check that string against your regular expression using QRegExp::exactMatch() function and if it don’t match then show tooltip.

    Connect the signal..

    ...    
    connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(onTextChanged(QString)));
    ...
    

    Here your slot goes..

    void MainWindow::onTextChanged(QString text)
    {
        QRegExp regExp;
        regExp.setPattern("[^0-9]*");  // For example I have taken simpler regex..
    
        if(regExp.exactMatch(text))
        {
            m_correctText = text;    // Correct text so far..
            QToolTip::hideText();
        }
        else
        {
            QPoint point = QPoint(geometry().left() + ui->lineEdit->geometry().left(),
                                  geometry().top() + ui->lineEdit->geometry().bottom());
    
            ui->lineEdit->setText(m_correctText);   // Reset previous text..
            QToolTip::showText(point,"Cannot enter number..");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two widgets, one arbitrary (usually a QLineEdit), and one QLabel which displays
Have deployed numerous report parts which reference the same view however one of them
I have a QTimeEdit which I want to set to some value and the
How is it possible to have qlineedit->settext() to accept file of type .ma only?
I have set property to QLineEdit as self.ui.txtName.setProperty('rules', 'required') I want to remove this
I have a QLineEdit inside a widget inside a QTabWidget. Let's say that tab
So currently I have code, in C++, that creates a few QLabels, a QLineEdit,
I have a QTableWidget that has a combination of QLineEdit and normal table cell
I have a console input in my Qt based application, it's a QLineEdit ,
I have a class which inherits QComboBox. I need to set red border for

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.