Left Align Text on Push Button

Find and share HowTos to various installations / configurations!
13 posts • Page 1 of 2
Gr1mst4r
Posts:11
Joined: Thu Apr 19, 2018 2:54 pm

Left Align Text on Push Button

Post by Gr1mst4r »

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

Post by adaneau »

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

Gr1mst4r
Posts:11
Joined: Thu Apr 19, 2018 2:54 pm

Re: Left Align Text on Push Button

Post by Gr1mst4r »

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

adaneau
Posts:310
Joined: Tue Feb 21, 2012 9:49 am

Re: Left Align Text on Push Button

Post by adaneau »

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.

Gr1mst4r
Posts:11
Joined: Thu Apr 19, 2018 2:54 pm

Re: Left Align Text on Push Button

Post by Gr1mst4r »

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

Post by mkoller »

The correct syntax is

Code: Select all

QPushButton[type="Nav_Button"] { ... }
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.

adaneau
Posts:310
Joined: Tue Feb 21, 2012 9:49 am

Re: Left Align Text on Push Button

Post by adaneau »

Hi,

Also just to be sure,

Using

Code: Select all

QPushButton[type="Nav_Button"] { ... }
implies that your button typename is Nav_Button ;)

If you wanna use a specific button only, then you can also do :

Code: Select all

QPushButton#myButtonName{ ... }
Where myButtonName is the name of your button.

Gr1mst4r
Posts:11
Joined: Thu Apr 19, 2018 2:54 pm

Re: Left Align Text on Push Button

Post by Gr1mst4r »

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

adaneau
Posts:310
Joined: Tue Feb 21, 2012 9:49 am

Re: Left Align Text on Push Button

Post by adaneau »

Ok, so far more explanation :)

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
So here is now my CSS:

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;
}
Hope it is helping

Gr1mst4r
Posts:11
Joined: Thu Apr 19, 2018 2:54 pm

Re: Left Align Text on Push Button

Post by Gr1mst4r »

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

13 posts • Page 1 of 2