PDA

View Full Version : QPushButton setText Alignment



rokkamraja
19th October 2009, 09:30
Hi All,

I have an external resource script in which I embed stringResources.txt -

Essentially stringResources.txt is a QMap< QString, QString > key, valu pairs. Now I read the entire file into a QMap
and I am trying to setText for different widgets using the key so that it can be dynamic and resources externalized.

I am successful at that, however, when I do a setText on PushButton or Checkbox widgets using this method I end up getting the text top centered. even If I do text-align in stylesheet,t here is no change.

I am attaching two screenshots - 1 with text top-centered and 2 the way I want and normally the way it works.

Please let me know what needs to be done or what I am doing wrong ?

Thanks,
Raja.

high_flyer
19th October 2009, 10:40
can you show how you are doing the text alignment in the style sheet?

rokkamraja
19th October 2009, 10:44
Hi,

The UI file generated code where I am getting the text correctly is as follows:
In the setupUi function -

QFont font7;
font7.setFamily(QString::fromUtf8("Helvetica"));
font7.setPointSize(10);
font7.setBold(true);
font7.setItalic(false);
font7.setWeight(75);
saveStream->setFont(font7);
saveStream->setStyleSheet(QString::fromUtf8("background-image: url(:/images/signup_here.png);\n"
"border:0px;\n"
"font-weight:600;\n"
"color:white;\n"
"\n"
"\n"
""));
pushButton = new QPushButton(m_qwidget_tab_network);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(190, 260, 141, 31));
QSizePolicy sizePolicy2(QSizePolicy::Ignored, QSizePolicy::Ignored);
sizePolicy2.setHorizontalStretch(0);
sizePolicy2.setVerticalStretch(0);
sizePolicy2.setHeightForWidth(pushButton->sizePolicy().hasHeightForWidth());
pushButton->setSizePolicy(sizePolicy2);
pushButton->setFont(font7);
pushButton->setStyleSheet(QString::fromUtf8("background-image: url(:/images/signup_here.png);\n"
"font-weight:600;\n"
"border:0px;\n"
"color:white;\n"
"text-align:center;"));

and after I run the setupUi method, in the constructor I am calling setText and calling in values from globalStrings ( ie. externalized strings ).


Thanks,
Raja.