I want to wordwrap in QPushButton. I tried put label on QPushbutton but that doesn't look good when mouse hover. So it tried paintEvent override method. but this is not work on stylesheet
how can i wordwrap property in QPushButton?
Related
ALL,
The QPushButton class has a member setIcon() which set the icon to be displayed on the button.
However, there is no parameter to set the icon alignment.
Is there a way to set the icon alignment for the QPushButton?
Thank you.
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.
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");
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
As far as I can tell, the way you make the background of a widget to be an image is to modify the qstylesheet to say:
background-image: url(<your image here>);
Which seems to work, unless it's the QDockWidget's main widget.
This is what I did:
Make a new qt widget project
Make a QWidget object, maybe put a button or two there to make sure you know it's being used.
Change the style sheet to the widget made in step 2 to contain: background-image: url(<your image here>);
In the MainWindow ui file, add the QDockWidget, promote it's main widget to the QWidget made in step #2.
When you run the program, you notice that the QDockWidget's background is still the default, however any buttons or labels you added to the widget have changed their backgrounds to the image you selected.
When you change the qss line from background-image to background-color, and select a color rather than an image, the widget does change color.
Does anyone have any suggestions for giving a QDockWidget a background image (and not just a background color)?
Apparently all you need to do is overwrite the widget's pain event with:
void MyWidget::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}