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]
-
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.
-
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;");
@ -
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);
@