I am creating a window using QT with C . The title of the window is a file name. I want to show(like tool tip) file path whenever I hover the mouse over the window title bar. How do I do this using QT?
CodePudding user response:
For adding ToolTip to your widgets or buttons you have 2 ways :
- if you create your UI from the Designer section :
RightClick in your button or widget and choose Change ToolTip
Then write what you want as ToolTip and also you can change its style by adding cone as HTML
like this :
Create your widget and then use setToolTip function
pushButton = new QPushButton(this); pushButton->setToolTip(QCoreApplication::translate("MainWindow", "
<span style=" font-size:12pt;">This is ToolTip
", nullptr));
CodePudding user response:
You can't do that, because you have no control over the title bar (outside removing it altogether). Forces from above are providing the so called window decoration and whenever a problem arises (like: "a text is not fully displayed in the title bar due to its length"), they take care of it in a reasonable way (e.g. they add ellipsis after the truncated text).
After you come to terms with this, you may ask yourself: why in heaven am I presenting sensible pieces of information in a title bar? Maybe that part of the UI is intended to show different information, maybe less vital? Maybe a long file name, which (apparently) must be read in its entirety, is better living in a label, maybe on top of the widget, i.e. in a meaningful place inside the part of the UI that is under my control.



