Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Items in the Grid component that are not Rectangle
Forum Updated to NodeBB v4.3 + New Features

Items in the Grid component that are not Rectangle

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    smileeFace
    wrote on last edited by
    #1

    Hi,

    Noticed something this morning, I feel that I might be overlooking something but I believe its worth asking. I am trying to place custom components in a Grid, but it seems like the components aren't placed into the grid. Or maybe they are but just into the first cell of the Grid. I don't know. What I would like is for the two circles to be next to each other. This might be intentional since the circle's and their text don't have "borders" where Grid can split them with.

    Circle.qml
    @
    import QtQuick 2.0

    Rectangle
    {
    id: circleContainer
    width: 100
    height: 100
    radius: 100
    color: "grey"
    }
    @

    Ellipse.qml
    @
    import QtQuick 2.0

    Path
    {
    id: point
    property real width: 200
    property real height: 200
    property real margin: 25
    property real centerX: width/2
    property real centerY: height/2
    property real relativeX: width/2 - margin
    property real relativeY: height/2 - margin
    property real magic: 0.551784
    property real magicX: relativeX * magic
    property real magicY: relativeY * magic

    startX: centerX
    startY: centerY - relativeY

    PathCubic { // Quadrant II arc
    control1X: point.centerX - point.magicX
    control1Y: point.centerY - point.relativeY
    control2X: point.centerX - point.relativeX
    control2Y: point.centerY - point.magicY
    x: point.centerX - point.relativeX
    y: point.centerY
    }

    PathCubic { // Quadrant III arc
    control1X: point.centerX - point.relativeX
    control1Y: point.centerY + point.magicY
    control2X: point.centerX - point.magicX
    control2Y: point.centerY + point.relativeY
    x: point.centerX
    y: point.centerY + point.relativeY
    }

    PathCubic { // Quadrant IV arc
    control1X: point.centerX + point.magicX
    control1Y: point.centerY + point.relativeY
    control2X: point.centerX + point.relativeX
    control2Y: point.centerY + point.magicY
    x: point.centerX + point.relativeX
    y: point.centerY
    }

    PathCubic { // Quadrant I arc
    control1X: point.centerX + point.relativeX
    control1Y: point.centerY - point.magicY
    control2X: point.centerX + point.magicX
    control2Y: point.centerY - point.relativeY
    x: point.centerX
    y: point.centerY - point.relativeY
    }
    }
    @

    EllipseView.qml
    @
    import QtQuick 2.0

    PathView
    {
    id: ellipseViewContainer
    width: parent.width
    height: parent.height
    interactive: false
    anchors.centerIn: parent
    path: Ellipse {
    width: ellipseViewContainer.width
    height: ellipseViewContainer.height
    }
    }
    @

    Selection.qml
    @import QtQuick 2.0

    Circle
    {
    id: selectionContianer
    anchors.centerIn: parent

    EllipseView
    {
    id: cycleSelectionEllipseView
    height: selectionContianer.height + 150
    width: selectionContianer.width + 150
    model: 16
    delegate: Text { text: index }
    }
    }
    @

    main.qml
    @import QtQuick 2.0

    Rectangle {
    id: background
    width: 500
    height: 360

    Grid
    {
    id: layout
    anchors.centerIn: parent
    rows: 1
    columns: 2
    spacing: 50

      Selection
      {
         id: select1
         height: 150
         width: 150
         color: "red"
      }
    
      Selection
      {
         id: select2
         color: "blue"
      }
    

    }
    }
    @

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      Your code was rather confusing. Using the names Ellipse and Circle in the same context when only one of them is a visible item is a bit weird :)

      I can however solve your problem. The only issue is your definition of Selection.qml. There you explicitly set @anchors.centerIn:parent@
      Anchors always wins over positioners, so despite your items correctly getting their x coordinates assigned by the Grid, it will simply be ignored due to placing the anchors there. (they both try to anchor to the center of the grid)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        smileeFace
        wrote on last edited by
        #3

        Oh, got it. Yeah I use different names in my actual code, I just tried to keep it similar.

        Thanks Jens!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved