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

  • Home
  • SEARCH
  • 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 874473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:06:31+00:00 2026-05-15T11:06:31+00:00

On a dialog I have a QLineEdit and a button. I want to enable

  • 0

On a dialog I have a QLineEdit and a button. I want to enable a tool tip for the QLineEdit(in it or under it) when I press the button. Please give me a code snippet.

  • 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-05-15T11:06:32+00:00Added an answer on May 15, 2026 at 11:06 am

    Here is a simple example:

    class MyWidget : public QWidget
    {
            Q_OBJECT
    
        public:
    
            MyWidget(QWidget* parent = 0) : QWidget(parent)
            {
                QVBoxLayout* layout = new QVBoxLayout(this);
                edit = new QLineEdit(this);
                layout->addWidget(edit);
                showButton = new QPushButton("Show tool tip", this);
                layout->addWidget(showButton);
                hideButton = new QPushButton("Hide tool tip", this);
                layout->addWidget(hideButton);
    
                connect(showButton, SIGNAL(clicked(bool)), this, SLOT(showToolTip()));
                connect(hideButton, SIGNAL(clicked(bool)), this, SLOT(hideToolTip()));
            }
    
        public slots:
    
            void showToolTip()
            {
                QToolTip::showText(edit->mapToGlobal(QPoint()), "A tool tip");
            }
    
            void hideToolTip()
            {
                QToolTip::hideText();
            }
    
        private:
    
            QLineEdit* edit;
            QPushButton* showButton;
            QPushButton* hideButton;
    };
    

    As you can see, there is no easy way to just enable the tool tip of some widget. You have to provide global coordinates to QToolTip::showText.

    Another way to do this is to create a QHelpEvent yourself and post this event using QCoreApplication::postEvent. This way, you can specify the text to be shown in your widget using QWidget::setToolTip. You still have to provide global coordinates, though.

    I am really interested in why you want to do this since tool tips are intended to be shown only when you hover your mouse or when you ask for the “What’s this” information. It looks like bad design to use it for something else. If you want to give a message to the user, why don’t you use QMessageBox?

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

Sidebar

Related Questions

I have dialog button and timepicker created in the same xml code below: <?xml
I have a dialog that I want to place within another dialog and position
I have a dialog box, created with the code javascript and HTML generated below.
I have a dialog application in which I want to have clickable menu items
I have Dialog in my activity, what I want is suppose the dialog is
I have some code where I have a button that I'd like to create
I have some custom made dialog that have on it Set Button , I
I have a button which on clicking opens jquery dialog. Inside that jquery dialog
I have a view with a button that opens a jquery dialog via partial
Issue: not able to close modal dialog I have the following code, it works

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.