4

I implemented a QTableWidget with 3 columns 1st and 2nd column is a combo box 3rd column is QLineEdit

I wanted to display a dialog which will serve as a hint similar to Qt when typing parameters for a function.

For example typing QString() will display a hint dialog with numbers 1 to 12 and the hint itself for the parameters of that function. This is different from auto-complete since it will display only a fixed number of messages in popup.

Please suggest any way to do this.

"hint" dialog or whatever it is called

Pirate X
  • 3,023
  • 5
  • 33
  • 60
steiryx
  • 71
  • 10
  • 1
    What about looking at the source of Qt Creator itself? http://code.qt.io/cgit/qt-creator/qt-creator.git/tree/src – maxik Jul 07 '16 at 08:52
  • 1
    Do not understand what you want, but look at `QWidget::setToolTip` method, `QToolTip` (provides tooltips show in any position in any time) and `QCompleter` classes. It also may be a custom `QWidget` with 'Qt::Popup' or `Qt::Tooltip`flags. – ilotXXI Jul 07 '16 at 10:09
  • 1
    I second @maxik 's comment. If you want to know how it's done, read the source. – jonspaceharper Jul 07 '16 at 12:58
  • Actually this is what I am doing after asking the question. Any idea on how to do that, I don't know where to start. Can I debug the Qt source code? – steiryx Jul 11 '16 at 02:12
  • @steiryx did you manage to get this working? Could you share your solution to help others with the same problem? Thanks! If you want to debug Qt source code you need debug information. You can get those by compiling Qt yourself for Debug Mode. – Mailerdaimon Aug 02 '16 at 06:38

3 Answers3

0

For QLineEdit what you usualy do is use the .setPlaceholderText( const QString & ) . Maybe that will work for your application .

Garjy
  • 467
  • 5
  • 12
  • "Setting this property makes the line edit display a grayed-out placeholder text as long as the line edit is empty." I think this will not display a dialog, it will only display a text inside the QLineEdit object. I wanted to display somewhat like dialog when I start typing on QLineEdit object. – steiryx Jul 07 '16 at 07:51
0

All QWidget objects have the function void setToolTip ( const QString & ) so you could do something like this:

QLineEdit *lineEdit= new QLineEdit();
lineEdit->setToolTip("Example");

Additionally, you have also the class QToolTip

Tarod
  • 6,732
  • 5
  • 44
  • 50
  • Thanks for the input. I will look into this, but first thing come into my mind is that it will only be triggered on hover not on action such as typing into QLineEdit object. – steiryx Jul 07 '16 at 09:18
  • According to the documentation, if you want to control a tooltip's behavior, you can intercept the `event()` function and catch the `QEvent::ToolTip` event. – Tarod Jul 07 '16 at 09:35
0

To show a tooltip at a widgets position you can do:

QToolTip::showText( widget->mapToGlobal( QPoint( 0, 0 ) ), tooltipText);

You can enter whatever position you want here. If you want to show colored text see this answer on SO.

Have a look at the documentation for a more detailed explanation.

Community
  • 1
  • 1
Mailerdaimon
  • 6,003
  • 3
  • 35
  • 46