QLabel text align wit StyleSheet
-
Did you try "setAlignment":http://doc.qt.nokia.com/4.7/qlabel.html#alignment-prop?
-
Sure, setAlignment works, but it has to be called from code. I'm interested in doing it with CSS style sheet.
[quote author="Eddy" date="1319480478"]Did you try "setAlignment":http://doc.qt.nokia.com/4.7/qlabel.html#alignment-prop?[/quote]
-
In the reference of text-align wrote:
@This property is currently supported only by QPushButton and QProgressBar.@ -
I am suggest to use
@padding-left@
But, i think, it is bad idea -
I didn't spot the "only supported" part in the doc. So it's not available yet... I guess I have to learn live without ;)
Thanks for the help.
-
Viktor, have you tried this? It works for me...
QLabel {
qproperty-alignment: AlignCenter;
} -
It works for me too, but can someone explain why?
[quote author="kajmano" date="1327775417"]Viktor, have you tried this? It works for me...
QLabel {
qproperty-alignment: AlignCenter;
}
[/quote] -
You can set any designable property using the qproperty-* syntax, which includes the alignment property.
-
Only for alignment properties or for all "supported property types":http://qt-project.org/doc/qt-4.8/stylesheet-reference.html#list-of-properties ?
-
You will have to distinguish between
- Properties as in "Style Sheet Properties":http://qt-project.org/doc/qt-4.8/stylesheet-reference.html#list-of-properties, like border, border-radius or background-color, which are part of the CSS specification
- Properties as in "Qt's Property System":http://qt-project.org/doc/qt-4.8/properties.html, like QLabel::alignment, QLabel::text or QLabel::wordWrap, which are part of a QObject's definition (using Q_PROPERTY)
You can use style sheets not only to set CSS properties, but also to set QObject properties, given that you prefix them with qproperty- (so for example to set the QLabel::alignment property you will have to use qproperty-alignment) so the engine knows you are referring to a QObject property, not a CSS property.
@
QLabel label;
label.setStyleSheet("border: 1px solid red;"
"border-radius: 3px;"
"background-color: white;"
"qproperty-alignment: AlignCenter;"
"qproperty-text: 'This is some rather long text.';"
"qproperty-wordWrap: true;");
@ -
Lukas, you made my day! I just tested it and it works like a charm.
The only thing that i dont get working is to set something like this:
@QLabel label;
label.setStyleSheet("qproperty-alignment: AlignBottom AlignRight;");
@ -
does this work ?
@
m_label1 = new QLabel;
m_label1->setText("<p style="color:red; text-align:justify;">The <strong>Qt</strong>kdkdkd didds hd duddbs shdydyd djudhdyddd dhdydysisi jdjfjfjf pgphohkgjfufh dhdhdbhfjfn fnhfhfhfkjf fjfhfhfjhjfn jfjfjdigdfkfi ifgjufhkfjjfi gigigjgj gifiuffhfk kjfjfj jjfjfjgfj kigkgkgkgk kiggigim </p>");
m_label1->setWordWrap(true);
m_label1->setAlignment(Qt::AlignJustify);
@ -
[quote author="Stefan Walter" date="1345718064"]The only thing that i dont get working ...[/quote]
You've forgotten the | (mind the quotes).
@
QLabel label;
label.setStyleSheet("qproperty-alignment: 'AlignBottom | AlignRight';");
@ -
Awesome, thanks a lot for all this tips.