Results 1 to 3 of 3

Thread: QPushButton setText Alignment

  1. #1
    Join Date
    Oct 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QPushButton setText Alignment

    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.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton setText Alignment

    can you show how you are doing the text alignment in the style sheet?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Oct 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushButton setText Alignment

    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.

Similar Threads

  1. QPushButton with image - text alignment
    By vladeck in forum Newbie
    Replies: 3
    Last Post: 1st July 2009, 19:20
  2. QPushButton SetText Color
    By Qt Coder in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2009, 17:21
  3. QPushButton setText problem
    By batileon in forum Qt Programming
    Replies: 3
    Last Post: 3rd December 2008, 03:02
  4. Qpushbutton
    By iamhere in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2008, 04:40
  5. QPushButton, stylesheets, text alignment
    By SiLiZiUMM in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2007, 19:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.