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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:43:25+00:00 2026-06-15T14:43:25+00:00

Under Windows, I’ve seen a nice feature: If I hover with the mouse over

  • 0

Under Windows, I’ve seen a nice feature: If I hover with the mouse over a short text field which contains overlong text not fitting completely into the field, a tooltip opens, displaying the complete contents of the text field.

Can someone point me to a code snippet which does this with QLineEdit?

  • 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-15T14:43:26+00:00Added an answer on June 15, 2026 at 2:43 pm

    I would create a custom class derived from QLineEdit like so:

    #ifndef LINEEDIT_H
    #define LINEEDIT_H
    
    #include <QtGui>
    
    class LineEdit : public QLineEdit
    {
        Q_OBJECT
    
    public:
        LineEdit();
    
    public slots:
        void changeTooltip(QString);
    };
    
    LineEdit::LineEdit()
    {
        connect(this, SIGNAL(textChanged(QString)), this, SLOT(changeTooltip(QString)));
    }
    
    void LineEdit::changeTooltip(QString tip)
    {
        QFont font = this->font();
        QFontMetrics metrics(font);
        int width = this->width();
    
        if(metrics.width(tip) > width)
        {
            this->setToolTip(tip);
        }
        else
        {
            this->setToolTip("");
        }
    }
    
    #include "moc_LineEdit.cpp"
    
    #endif // LINEEDIT_H
    

    Then just add it to whatever:

    #include <QtGui>
    #include "LineEdit.h"
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        LineEdit edit;
    
        edit.show();
    
        return app.exec();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Under Windows XP WPF true 3D content (which is usually displayed using the Viewport3D
Which X11 forwarding under Windows solution do you recommmend ? I'd like to get
I am running my code in R (under Windows) which involves a lot of
I'm trying to compile this program under Windows (it's a program which turns bootable
I just installed the Sublime Text under Windows Vista, and even following the advice
Under windows, when Evernote is installed, an api is also installed, which can be
Under Windows 7 I have a batch file for checking the status of some
Under Windows, I have used a program called Dependency Walker to examine the libraries
Under windows, this F# code will extend a file from say 12 bytes out
I am creating screenshots under Windows and using the LockBits function from GDI+ to

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.