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. [solved] Create a custom view
Forum Updated to NodeBB v4.3 + New Features

[solved] Create a custom view

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.0k 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.
  • M Offline
    M Offline
    Merinas
    wrote on last edited by
    #1

    Hi,

    I tried to create a custom view. I want to place my Component on a circle for that i used a Repeater. I've done something like that :
    

    @Item
    {
    id:root
    property alias model :rept.model
    property int size: 100

    Rectangle
    {
    id:area
    anchors.fill: parent
    anchors.margins: size/2

    Repeater
    {
    id:rept

    Image
    {
    width:size
    height:size
    x: area.width/2*(1+Math.cos(6.28/rept.countindex))-width/2
    y: area.height/2
    (1+Math.sin(6.28/rept.count*index))-height/2
    source:"img/"+iconFile //see model
    }
    }
    }
    }@

    That's working fine. But now I want to add a delegate to let the user place anything he wants, in this view. I know how to add a property Component for the delegate but how should i use it to duplicate the delegate for each item of the model?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Hi,

      You could try using a Loader for this (using e.g. the sourceComponent property).

      Also, have you looked into PathView at all? It might be an alternative for providing a circular view.

      Regards,
      Michael

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Merinas
        wrote on last edited by
        #3

        Yes, I look around PathView. But I failed to add a variable number of points in my path. Like i can't use (or manage) Repeater.

        I guess it's more interesting to did it without a pathView, just for challenge and learning. :)

        Anyway, I will check Loader and if I failed I will use a PathView.
        Thanks

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Merinas
          wrote on last edited by
          #4

          I've finished my custom view, thanks again for the advice, it was really helpful.

          For the record, I show you my solution :

          @import QtQuick 1.0

          Item {
          id:area

          property alias model: rept.model
          property Component delegate:Component { Rectangle{} }

          property real s: Math.sin(Math.PI/rept.count)
          property real w_item: area.width*(s/(1+s))
          property real h_item: area.height*(s/(1+s))

          property real w_circle: area.width-area.w_item
          property real h_circle: area.height-area.h_item

          Repeater
          {
          id:rept
          Loader
          {
          sourceComponent: delegate;
          width : area.w_item
          height:area. h_item
          x: area.w_circle/2*(1+Math.cos(2Math.PI/rept.countindex))
          y: area.h_circle/2*(1+Math.sin(2Math.PI/rept.countindex))
          }
          }
          }@

          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