Results 1 to 18 of 18

Thread: QListView ~ Center items horizontally

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView ~ Center items horizontally

    Quote Originally Posted by scgrant327 View Post
    Isn't that what I'm already doing?
    I don't know, you are not posting enough of the delegate to see if you are e.g. horizontally anchoring the column inside its parent.
    We can only see that you are not anchoring the text inside the column

    Cheers,
    _

  2. #2
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QListView ~ Center items horizontally

    Post #6 above has the full code.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView ~ Center items horizontally

    Ah, then my suggestion in comment #9 still applies.

    Cheers,
    _

  4. #4
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QListView ~ Center items horizontally

    Again... #10.

    Aren't I already doing that? If not, then were am I going wrong?

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView ~ Center items horizontally

    Quote Originally Posted by scgrant327 View Post
    Again... #10.
    But maybe I am just not seeing the correct code, can you point out where in which line in the code snippet of #10 you are using anchors?

    Cheers,
    _

  6. #6
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QListView ~ Center items horizontally

    Qt Code:
    1. 13. Component {
    2.  
    3. 14. id: boatAlphaDelegate
    4.  
    5. 15. Item {
    6.  
    7. 16. id: boatAlphaContainer
    8.  
    9. 17. width: parent.width
    10.  
    11. 18. anchors.horizontalCenter: parent.horizontalCenter
    12.  
    13. 19. height: Funcs.pointHeight(14)
    14.  
    15. 20. Column {
    16.  
    17. 21. Text {
    18.  
    19. 22. font.pixelSize: Funcs.fontHeight(12)
    20.  
    21. 23. text: boatAlphaName
    22.  
    23. 24. horizontalAlignment: Text.AlignHCenter
    24.  
    25. 25. }
    26.  
    27. 26. }
    28.  
    29. 27.
    30.  
    31. 28. MouseArea {
    32.  
    33. 29. id: boatAlphaMouseArea
    34.  
    35. 30. anchors.fill: parent
    36.  
    37. 31. hoverEnabled: true
    38.  
    39. 32. onClicked: {
    40.  
    41. 33. boatAlphaList.currentIndex = index
    42.  
    43. 34. }
    44.  
    45. 35. }
    46.  
    47. 36. }
    48.  
    49. 37. }
    To copy to clipboard, switch view to plain text mode 

    Lines 18 & 24?

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView ~ Center items horizontally

    Line 18 has no effect, since the item is as wide as its parent.

    Line 24 is no anchor and, as previously explained, has no effect since the Text element has just enough width to hold the text.
    Basically the same result as line 18.

    In order to center something inside something else, the first needs to be smaller than the latter, or the latter needs to be bigger.

    So what you have is
    - a Text element that is just wide enough to display the text
    - a Column element that is just as wide and positioned at 0/0 (default position)

    What you want is
    - a Column element that is larger than the Text, probably as wide as its parent
    - either a Text element horizontally anchored in it or a Text element with the same width and using alignment

    Cheers,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    scgrant327 (15th March 2016)

  9. #8
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QListView ~ Center items horizontally

    Thanks for pointing me in the right direction:

    What you want is
    - a Column element that is larger than the Text, probably as wide as its parent
    - either a Text element horizontally anchored in it or a Text element with the same width and using alignment

Similar Threads

  1. Replies: 7
    Last Post: 9th September 2013, 08:31
  2. Center icon in QListView using QStyledItemDelegate
    By franki in forum Qt Programming
    Replies: 1
    Last Post: 11th June 2013, 08:53
  3. How to align list items to the center?
    By zgulser in forum Qt Tools
    Replies: 4
    Last Post: 9th February 2009, 09:52
  4. Center TabBar horizontally on the TabWidget
    By forrestfsu in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2007, 14:26
  5. Q3listbox center items
    By sreedhar in forum Qt Programming
    Replies: 3
    Last Post: 24th February 2006, 11:21

Tags for this Thread

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.