Is there a possibility to add a tooltip to a QPushButton. I mean, that when you roll over the button a small textbox appears (usually yellow) and tells users what this button is doing.
Thank you.
QPushButton is a QWidget, so it has the setToolTip(const QString&) like all other widgets.
Either that's what you're looking for, or you're after the setWhatsThis(const QString&) function. More info in the QWhatsThis documentation.
Related
I would like to implement a group of pushButtons like painting tool chose in Adobe Ps:
only one button can be checked at any time
keep button be down after I click it
I have used setAutoExclusive(true) to meet the first requirement. So the next step is to deal with the second... Please give me some advice or suggestion?
QPushbutton button;
button->setCheckable(true);
or just click on the "Checkable" check box in designer
Like suggested by another answer, you can create a QPushButton by e.g.
button = new QPushButton("Button text", this);
and then make it checkable with
button->setCheckable(true);
For this to have a visual effect, you need a section in your stylesheet (.qss) for
QPushButton:checked. If you have a section for QPushButton:pressed, you can just add it there, i.e. change
QPushButton:pressed {
to
QPushButton:pressed,
QPushButton:checked {
If you don't, the styling you need depend on the appearance of the button in its pressed state, which in turn depends on your operating system, so you have some guesswork to do.
I am trying to develop a functionality using Qt which I don't know whether it is possible to implement. Here is the requirement:
When the user hovers over a node (an object derived from QGraphicsItem), a window will be shown near the node, in the window there might be some histograms or buttons that can be clicked to show further information. When the mouse leaves the window, it will automatically close.
I tried to use a tooltip, because it can pop-up near the node and close when the mouse leaves it, but it can only show text. So, it still cannot work that way. I am wondering if there is another way to do this? I did lots of google search, but there is still no answer.
Thanks so much for helping me with this.
If you're ok with using a 3rd party library, Qxt provides a class that provides a tooltip that is QWidget based, which will let you use an arbitrary widget as the tooltip rather than just text.
See: Qxt::ToolTip
you don't have to use tooltip for your app
you can use or call widget or dialog, on hover mouse event
Please refer Qt Example EmbeddedDialog Example, It is advanced, But you can understand how hover Enter/Leaving events are working. I personally prefer don not create instance of Popupdialog for each item, create it if only nesessary. Otherwise create one dialog and pass its reference to all the items through the constructor initialization.
1. These are the API you are intrested on, reimplemet this.
QGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) and void QGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
2. When You create Dialog, You can pass Qt::WindowFlags as Qt::ToolTip.
I want to create a squared radio button, with the text inside the button. Is that possible? I think the button shape could be changed trough css, but what about the text?
Any hint?
Rather than trying to deform a QRadioButton into something which visually resembles a QPushButton, I would simply use a QPushButton with some custom logic.
You won't have to worry about the visual aspect then, while the logic itself is not all that hard to write.
As stated by #besworland, QPushButton inherits from QAbstractButton, which already has the option to be checkable or not. You can set this via setCheckable(bool).
To mimic the "exclusive" behaviour of a set of QRadioButtons, you can add your buttons to a QButtonGroup and make it an exclusive one. As stated in the documentation "An exclusive button group switches off all checkable (toggle) buttons except the one that was clicked." You can use a QButtonGroup's setExclusive(bool) method for that.
In any case, I would consider those easier options than transforming a QRadioButton to fit your needs.
It looks like a label normally, once you move the mouse over it, or clicked it, then will turn to be a edit control or combobox likewise.
Use a QStackedWidget. According to the docs, "The QStackedWidget class provides a stack of widgets where only one widget is visible at a time." You can then reimplement QWidget::enterEvent and QWidget::leaveEvent to detect mouse overs and show the appropriate widget.
I have a QLabel without any text but with a QPixmap image. I can not figure out a way to open a url when the user clicks the image. I can not use text in QLabel here.
You don't need to put text in, but you do need to switch to either a subclassed label or to use a QPushButton instead. If you use a QPushButton (which is the easiest) then you can change the relief layout so it looks flat again (since the default button doesn't).
You could install an event filter on the label and filter for mouse press events. For an example, see my answer to a similar question.