Left Align Text on Push Button
- Gr1mst4r
- Posts:11
- Joined: Thu Apr 19, 2018 2:54 pm
Left Align Text on Push Button
I am trying to left align the text on a push button but push buttons do not appear to work with the normal alignment properties. Can left alignment achieved either via GEDI or programmatically?
- adaneau
- Posts:310
- Joined: Tue Feb 21, 2012 9:49 am
Re: Left Align Text on Push Button
Hi,
Have you tried with CSS?
Seems to me the way to go, using padding or margin to put text in good place.
QPushButton
{
Text-align:left;
}
http://doc.qt.io/qt-5/stylesheet-examples.html
Edit: Align property that you mentioned is for layout and not for text inside the button.
BR
Alex
Have you tried with CSS?
Seems to me the way to go, using padding or margin to put text in good place.
QPushButton
{
Text-align:left;
}
http://doc.qt.io/qt-5/stylesheet-examples.html
Edit: Align property that you mentioned is for layout and not for text inside the button.
BR
Alex
- Gr1mst4r
- Posts:11
- Joined: Thu Apr 19, 2018 2:54 pm
Re: Left Align Text on Push Button
Thanks for the prompt reply.
I have created a css file, (stylesheet.css), in the config directory but it doesn't have any effect on the text alignment of the button. Do I need to do anything to link the style sheet to the push button?
Joe
I have created a css file, (stylesheet.css), in the config directory but it doesn't have any effect on the text alignment of the button. Do I need to do anything to link the style sheet to the push button?
Joe
- adaneau
- Posts:310
- Joined: Tue Feb 21, 2012 9:49 am
Re: Left Align Text on Push Button
Hi,
Did you restarted your UI? Otherwise style will not be used (you can also click edit / reload stylesheet).
I tried on my 3,16 and it works fine.
Did you restarted your UI? Otherwise style will not be used (you can also click edit / reload stylesheet).
I tried on my 3,16 and it works fine.
- Gr1mst4r
- Posts:11
- Joined: Thu Apr 19, 2018 2:54 pm
Re: Left Align Text on Push Button
Many apologies, my post was unclear. I can left align all QPushButtons or none. I only want a certain type of button, "Nav_Button", to left align. When I try to use the QPushButton[type="Nav_Button"] or QPushButton>"Nav_Button" options, nothing left aligns.
- mkoller
- Posts:741
- Joined: Fri Sep 17, 2010 9:03 am
Re: Left Align Text on Push Button
The correct syntax is
The latter is syntactically wrong. if you had both in your css file, probably the UI did not use any settings since the parsing failed with a syntax error.
Code: Select all
QPushButton[type="Nav_Button"] { ... }
- adaneau
- Posts:310
- Joined: Tue Feb 21, 2012 9:49 am
Re: Left Align Text on Push Button
Hi,
Also just to be sure,
Using
implies that your button typename is Nav_Button
If you wanna use a specific button only, then you can also do :
Where myButtonName is the name of your button.
Also just to be sure,
Using
Code: Select all
QPushButton[type="Nav_Button"] { ... }If you wanna use a specific button only, then you can also do :
Code: Select all
QPushButton#myButtonName{ ... }- Gr1mst4r
- Posts:11
- Joined: Thu Apr 19, 2018 2:54 pm
Re: Left Align Text on Push Button
Thanks for the prompt replies.
Unfortunately no luck, here are the four attempts at modifying the css;
QPushButton
{
Text-Align:Left;
}
The code above aligned all text on all push buttons to the left.
QPushButton[type="Nav_Button"]
{
Text-Align:Left;
}
The code above had no effect on any push button.
QPushButton#"Nav_Button"
{
Text-Align:Left;
}
The code above had no effect on any push button.
QPushButton#Nav_Button
{
Text-Align:Left;
}
The code above had no effect on any push button.
The object is called Nav_Button and is saved in a nested folder under objects, but I haven't modified the Typename.
Regards,
Joe
Unfortunately no luck, here are the four attempts at modifying the css;
QPushButton
{
Text-Align:Left;
}
The code above aligned all text on all push buttons to the left.
QPushButton[type="Nav_Button"]
{
Text-Align:Left;
}
The code above had no effect on any push button.
QPushButton#"Nav_Button"
{
Text-Align:Left;
}
The code above had no effect on any push button.
QPushButton#Nav_Button
{
Text-Align:Left;
}
The code above had no effect on any push button.
The object is called Nav_Button and is saved in a nested folder under objects, but I haven't modified the Typename.
Regards,
Joe
- adaneau
- Posts:310
- Joined: Tue Feb 21, 2012 9:49 am
Re: Left Align Text on Push Button
Ok, so far more explanation
Let we say I have 3 push buttons:
Hope it is helping
Let we say I have 3 push buttons:
- One classic without any special name or typename
- One with a special name NavButton
- One with a special typename NavButton
Code: Select all
/*this is only for button named NavButton*/
QPushButton#NavButton
{
Text-align:right;
}
/*this is only for button from type NavButton*/
QPushButton[type="NavButton"]
{
Text-align:left;
}
/*this is for all buttons*/
QPushButton
{
Text-align:center;
}
- Gr1mst4r
- Posts:11
- Joined: Thu Apr 19, 2018 2:54 pm
Re: Left Align Text on Push Button
Hi,
As I mentioned earlier I have tried all of those options, individually by the way they aren't all in the css file simultaneously.
Everytime I modify the css file I reload the css file from the GEDI whenever I revert back to the code below
QPushButton
{
Text-Align:Left;
}
all text on all buttons moves to the left as expected, but should I add any of the options mentioned above all text in all buttons becomes centre aligned.
Adding the [type="NavButton"] and #NavButton options after QPushButton has no effect.
Regards,
Joe
As I mentioned earlier I have tried all of those options, individually by the way they aren't all in the css file simultaneously.
Everytime I modify the css file I reload the css file from the GEDI whenever I revert back to the code below
QPushButton
{
Text-Align:Left;
}
all text on all buttons moves to the left as expected, but should I add any of the options mentioned above all text in all buttons becomes centre aligned.
Adding the [type="NavButton"] and #NavButton options after QPushButton has no effect.
Regards,
Joe