Results 1 to 10 of 10

Thread: QCombBox with right-justified text

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCombBox with right-justified text

    Changing the layout direction does move the down arrow to the left, but that's not where I expect it to be. I will look at the custom delegate solution tomorrow.

  2. #2
    Join Date
    Oct 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCombBox with right-justified text

    Qt Code:
    1. combo->setStyleSheet(QString::fromAscii("QComboBox QListView {padding-right: 20px;}"));
    To copy to clipboard, switch view to plain text mode 
    gives is close to what I want. (QListView could be QAbstractItemView and padding could be margin with the same visual effect.) The 20px width should be derived from combo somehow, not pulled from thin air. It would also look better if the pulldown did not extend under the arrow.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QCombBox with right-justified text

    You can always create your own style of course.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QCombBox with right-justified text

    Quote Originally Posted by wssddc View Post
    Qt Code:
    1. combo->setStyleSheet(QString::fromAscii("QComboBox QListView {padding-right: 20px;}"));
    To copy to clipboard, switch view to plain text mode 
    Better use QLatin1String since it is faster.

    The 20px width should be derived from combo somehow, not pulled from thin air
    As told, look at QStyle. QStyle::subControlRect()

  5. #5
    Join Date
    Oct 2010
    Posts
    1
    Qt products
    Platforms
    Unix/X11

    Default Re: QCombBox with right-justified text

    This is more simple than you think. My solution is in Python and PyQt, but you should be able to see the similarities.

    Qt Code:
    1. comboBox = QComboBox()
    2. view = comboBox.view()
    3. view.setLayoutDirection(Qt.RightToLeft)
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Oct 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCombBox with right-justified text

    Setting the layout direction to right-to-left moves the text in the pulldown further to the right than I want. What I would like is for the pulldown to not extend under the arrow. What's happened since my original posting is I said I would release my application when Qt 4.7 was ready. Well 4.7 was released a few days after my post, and I'm still not quite ready to release. I've stopped working on this relatively minor cosmetic issue for, as Qt bug reports often say, some future release of my program.

Similar Threads

  1. Replies: 0
    Last Post: 2nd August 2010, 09:37
  2. Replies: 3
    Last Post: 3rd May 2009, 08:58
  3. Replies: 1
    Last Post: 3rd September 2008, 14:16
  4. Qt class showing text area/text edit
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 21st August 2008, 12:15
  5. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45

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.