QToolButton - html text - qt

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");

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 Space Between Text and Icon

I have a QToolButton. I wanted text and icon to be on it. I set button style by setToolButtonStyle(Qt::ToolButtonTextBesideIcon).
But icon and text are so close to each other. Is there a method to give some space between icon and text by css?
You can't. There is no such a property neither for QToolButton (nor for QPushButton). All the properties for these buttons are in the documentation.
One thing you can do is to create your own class inheriting from QToolButton and overriding the paintEvent(). In this function, you will manually place your icon.
This is the shortest solution, but if you're brave enough, there are longer paths, like creating your own button subclassing directly QWidget (but in this case, you will need to implement ALL its behavior).
You can achieve it although this is not the documented solution.
Just provide spaces in QPushButton text start. By Doing this, icon and text will automatically go far from each other.

Qt QPushbutton Icon underneath Text

When I create a QPushButton with an Icon it by default displays the text to the right of the icon. Is there a way to have the text display above the icon?
The easiest way is to use a QToolButton instead. This class has a method named setToolButtonStyle, which allows you to do exactly what you want.
In C++ (I have never messed with PyQt):
QToolButton *button = new QToolButton(this);
button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
Link to the C++ docs: QToolButton and Qt::ToolButtonStyle

How can we create hyper link text in QtGui?

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

Text under a widget added with QToolbar.addWidget()

I have a QToolbar with toolButtonStyle set to Qt::ToolButtonTextUnderIcon in which I add a QLineEdit through addWidget(). I'd like to have descriptive text under that widget like I do with other buttons, but I don't know how to do it or if it's even possible. I tried:
lineEdit = QLineEdit()
action = self.toolBar.addWidget(lineEdit)
action.setText("Some Text")
But it doesn't work. Is it possible at all? If not, are there special techniques I don't know about to put text under that widget in a way that it's aligned with the other labels regardless of the style?
toolButtonStyle refers to buttons' label position only, while you're adding a QLineEdit.
To put a label under your line edit try arranging a layout, a QVBoxLayout for example

Resources