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.
Related
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.
By default, the text is always on the right-side of the tab icon...
What should I do to move the text to the bottom of it ?
And is there an option to do icon/text alignment ??
(I'm designing the GUI base on Qt Creator Designer.
I'm trying with Qt stylesheet but I can't. I have not yet modify the code that generated by Qt Designer.)
Thank you very much!
A tricky way:
Since we can set QToolButton to be icon above text, just create a group of QToolButtons, listed horizontally or vertically, each button needs to be checkable. Add them to a QButtonGroup.
Then hide the TabBar of QTabWidget(out of parent widget or under ToolButtons), place the TabWidget under the listed ToolButtons.
Finally, connect the QButtonGroup buttonClicked signal to the TabWidget's setCurrentIndex signal.
Notice, when you add a button to QButtonGroup, you will have to assign the ID from 0 manually.
I set corner widget into QMenuBar that has two QPushButtons. But when I set long text by button's setText, button doesn't change it's weight, so, icon and part of text hiding. So, how to change button's width and width of corner widget when set text?
Call menuBar()->adjustSize();after setting the text on the button.
I resolved it by setting the same corner widget into QMenuBar again after changing button text.
I think the default size is too small. Any way to change it? Thanks.
QToolbar has iconSize property.
As far as I know, the only way to change QMenu icon size is to create a custom style for it. You can read about it here
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