How can we create hyper link text in QtGui? - qt

I want to display some hyperlink text in my window so that it will respond to user click event.

A QLabel supports HTML markup and can easily be added to any QWidget.
Another easy way to do this is to have a borderless flat QPushButton.

You can do it by using QLabel. QLabel::setOpenExternalLinks(bool) and you have to set the text of the label to be in html format text

Related

How make text at button under the icon?

How make text at button under the icon with qss ?
qustion how do it at QPushbutton, not at toolbutton.
There would be more solutions to your question but, I prefer to use QToolButton instead of using QPushButton and set toolButtonStyle property to ToolButtonTextUnderIcon. To do it fast in ui file right click on your QPushButton and choose morph into QToolButton.

QToolButton - html text

Is it possible to format QToolButton text with HTML like in QLabel? toolbutton.SetText("Text <b>Test</b>") doesn't work
I don't think this is possible without subclassing QToolButton and overriding the paintEvent, but if you just want to style the text in the button, you can use Qt Style Sheets like this:
toolButton->setStyleSheet("font-weight: bold");

QLabel auto multiple lines

For example, we have a QLabel with MaximumWidth set to 400.
When we try to display some text with pixel width more than 400, it's shown cut off.
Is there any way to make QLabel display this string in multiple lines without using QFontMetrics or the like?
If I understood your question correctly, you should use the setWordWrap function for your label, with true as its parameter.
QLabel lbl("long long string");
lbl.setWordWrap(true);
In order to show multiple lines in QLabel, right click on QLabel and select 'change rich text'. This brings up dialog where you can type the text as you want to see including enter key. Setting the word wrap is not required for this.
If you set the word wrap as well (in QLabel properties) than it will wrap each individual line in the Qlabel if it was longer than the real estate.
As another option to wrap text using Qt Designer, you can check the box under Property Editor for a QLabel:

While we are using Qlabel as hyperlink text how we can remove the line below the hyperlink text in normal state?

I want the line to appear only when we hovered or press the hyperlink text not in normal state and i want to change the color of the text also. i have tried Qpalette but i found no change in color.
You can add a style attribute to your anchor tag:
QLabel *label = new QLabel("<a style='text-decoration:none' "
"href='http://www'>your link</a>);
See the HTML subset supported by Qt's rich-text widgets for details.

How to make a QTextEdit fill its parent dialog?

I've been using Qt for some times, but I'm quite new to layouts. I would like to create a dialog with a QTextEdit inside, and the QTextEdit would resize to fill the whole dialog. How can I use layouts to do that? Or is there some other technique that I'm missing?
I have tried adding a layout to the dialog, then put the QTextEdit inside. However, I cannot find any property to make the layout fit the whole dialog.
After adding the text edit to your form, right click on the form and you will see a "Lay out" menu item at the bottom of the context menu, select that and then the layout type you want to use. The designer will create a top level layout of that type for your form and the text edit should now expand to fill the form.

Resources