Results 1 to 1 of 1

Thread: RTL QPushButton displays undesired alignment of text and icon

  1. #1
    Join Date
    Jun 2012
    Location
    Iowa City, IA
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default RTL QPushButton displays undesired alignment of text and icon

    Hi,

    I am using QPushButton with an icon and text, and the desire is for them to be left-aligned as shown in the first screenshot. My application is translatable to Arabic and therefore I have RTL support. When reversing the layout of the button to RTL, I would like it to just be a mirror image; because my stylesheet says to align left and the button layout is set to RTL, Qt automatically should align everything to the right. However, I get the unexpected results as shown in the second screenshot. This code example is pretty bare bones but I've attached main.cpp and the ui file for reference. Here is the important section of code from the cpp:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent)
    5. : QMainWindow(parent)
    6. , ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9.  
    10. ui->pushButton->setText("TheImage");
    11. ui->pushButton->setIcon(QIcon(":/TheImage"));
    12. ui->pushButton->setStyleSheet("text-align: left");
    13. ui->pushButton->setLayoutDirection(Qt::RightToLeft);
    14. }
    15.  
    16. MainWindow::~MainWindow()
    17. {
    18. delete ui;
    19. }
    To copy to clipboard, switch view to plain text mode 

    Appreciate any suggestions!
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. Replies: 1
    Last Post: 4th April 2011, 19:41
  2. [QPushButton] text below icon
    By Tomasz in forum Newbie
    Replies: 10
    Last Post: 3rd December 2010, 15:06
  3. QPushButton with image - text alignment
    By vladeck in forum Newbie
    Replies: 3
    Last Post: 1st July 2009, 19:20
  4. QPushButton, stylesheets, text alignment
    By SiLiZiUMM in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2007, 19:53
  5. Icon Text Alignment
    By nupul in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 04:47

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.