Results 1 to 3 of 3

Thread: Text Alignment in QMainWindow Widget

  1. #1
    Join Date
    Jan 2008
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Text Alignment in QMainWindow Widget

    I'm designing a MainWindow application that contains a single menu item which I wanted to appear on the RHS of the menuBar. To accomplish this, I set the layoutDirection to RightToLeft.

    However, this had some unusual consequences:

    One of my pushButtons had the text, 'Do the operation?' which appeared as, '?Do the operation' I had to re-write as, '?Do the operation' to have it appear correctly.

    All the QLineEdits had their text right justified. To get left justify, I had to insert a lineEdit->setAlignment( Qt::AlignRight).
    All the QTextEdits appeared correctly left justified.

    Should I expect the layoutDirection of the parent to impact some of the children?

    I'm using version 4.4.3. O/S is WindowsXP and 7.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Text Alignment in QMainWindow Widget

    Prior to Qt 4.7 setting the QWidget::layoutDirection() also set the text direction. English is left-to-right but is being treated as if it is right to left. I am not sure if switching to 4.8 will achieve what you want.

    Do you really want to design a non-standard menu bar anyway?

  3. #3
    Join Date
    Jan 2008
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Text Alignment in QMainWindow Widget

    My naive approach was to change the layout direction of the entire QMainWindow widget which resulted in several problems. I now realize that individual components of QMainWindow can be modified. The following in either the constructor or in the createMenu() module accomplishes the desired layout:

    menuBar()->setLayoutDirection( Qt::RightToLeft);

Similar Threads

  1. QComboBox text alignment
    By mentalmushroom in forum Qt Programming
    Replies: 1
    Last Post: 31st January 2012, 21:33
  2. Replies: 2
    Last Post: 29th June 2011, 15:45
  3. Text Alignment in a ListWidget
    By Krish_ng in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2007, 02:19
  4. QToolButton text alignment
    By Vladimir in forum Qt Programming
    Replies: 6
    Last Post: 2nd March 2007, 07:42
  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
  •  
Qt is a trademark of The Qt Company.