Results 1 to 6 of 6

Thread: center items in Grid View cells

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default center items in Grid View cells

    Hi,

    Any idea how to center the delegate item which has smaller dimensions compared to the cell dimensions?
    They're always aligned on the top left.

    Grid View Code:
    Qt Code:
    1. GridView
    2. {
    3. id: preferencesList
    4. anchors.horizontalCenter: parent.horizontalCenter
    5. anchors.verticalCenter: parent.verticalCenter
    6. width: 350; height: 350
    7. cellWidth: 175; cellHeight: 175
    8. delegate: delegates {}
    9. }
    To copy to clipboard, switch view to plain text mode 

    delegates:
    Qt Code:
    1. Item
    2. {
    3. id: root
    4. width: GridView.view.cellWidth
    5. height: GridView.view.cellHeight
    6.  
    7. Rectangle
    8. {
    9. width: 130
    10. height: 130
    11. anchors.centerIn: parent.Center // this is not working
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    I already tried putting the center anchor in the root item, still not working.
    Thanks.

  2. #2
    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: center items in Grid View cells

    centerIn and fill anchors take an item id

    Qt Code:
    1. anchors.centerIn: parent
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    joko (26th November 2014)

  4. #3
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: center items in Grid View cells

    Quote Originally Posted by anda_skoa View Post
    centerIn and fill anchors take an item id

    Qt Code:
    1. anchors.centerIn: parent
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _
    Thanks for the quick response anda_skoa.
    Where should I put the centerIn and fill anchors? At the Rectangle of the Item?

    I don't want to fill the Rectangle into the cell because I want to limit the delegate mouseArea into the smaller dimension instead of the whole cell.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: center items in Grid View cells

    Quote Originally Posted by joko View Post
    Where should I put the centerIn and fill anchors? At the Rectangle of the Item?
    Exactly where you have it now, just fix the binding expression.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    joko (26th November 2014)

  7. #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: center items in Grid View cells

    Quote Originally Posted by joko View Post
    Where should I put the centerIn and fill anchors? At the Rectangle of the Item?
    centerIn and fill are obviously anchor options that rule each other out, right?

    Quote Originally Posted by joko View Post
    I don't want to fill the Rectangle into the cell
    Where did I say you had to fill it?

    Cheers,
    _

  8. #6
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: center items in Grid View cells

    Quote Originally Posted by anda_skoa View Post

    Where did I say you had to fill it?

    Cheers,
    _
    Sorry, i miss understood your previous comment, I thought I should fill the Rectangle into Item.

    All good now! Cheers to both of you!

Similar Threads

  1. Replies: 1
    Last Post: 20th October 2014, 17:51
  2. Replies: 7
    Last Post: 9th September 2013, 08:31
  3. Replies: 6
    Last Post: 16th February 2010, 18:21
  4. How to align list items to the center?
    By zgulser in forum Qt Tools
    Replies: 4
    Last Post: 9th February 2009, 09:52
  5. Q3listbox center items
    By sreedhar in forum Qt Programming
    Replies: 3
    Last Post: 24th February 2006, 11:21

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.