[Interest] QML issue with putting an element on top of a repeater item based on the clicked one

Mark markg85 at gmail.com
Fri Jun 29 20:41:43 CEST 2012


On Fri, Jun 29, 2012 at 8:30 AM, Bo Thorsen <bo at fioniasoftware.dk> wrote:
> Hi Mark,
>
> This might not be the best advice, because I don't know your reasons for
> choosing the repeater.
>
> Something tells me the reason you have problems is that you shouldn't
> use a repeater. I mean, what are you repeating? If you do different zoom
> levels in a calendar application, the hours are usually painted
> differently, which makes a repeater a bit weird.
>
> Repeaters are great for doing something quick. But sometimes you have to
> get rid of them later, because they get in your way.
>
> Hard to say if this really is the core of your problem, but it's worth
> thinking about.
>
> Bo.
>
> Den 29-06-2012 01:04, Mark skrev:
>> Hi,
>>
>> Sorry for the long title, i don't really know how to describe this
>> issue otherwise.
>>
>> First for the code.
>>
>> File: CalendarDay.qml
>> http://paste.kde.org/509612/
>>
>> main.qml
>>
>> import QtQuick 1.1
>>
>> Rectangle
>> {
>>      width: 800
>>      height: 600
>>
>>      CalendarDay
>>      {
>>          anchors.fill: parent
>>      }
>> }
>>
>> What i'm trying to achieve is the same as in iCal :
>> http://ompldr.org/vZWpvcw I'm trying to get the "green" thing places
>> on the cells that i select. Now i already can trace which rectangle
>> i'm clicking by means of childAt and that seems to be working just
>> fine. What i did then is adding just a red square that i want to place
>> at the bottom position of the clicked row. That is where i get stuck.
>>
>> What i'm trying to do now is anchoring the red rectangle to the
>> "anchors.bottom" from the clicked rectangle (done in the code on line
>> 250 in the paste link). I tried item.bottom and item.anchors.bottom,
>> the latter one complained about a null object..? That however isn't
>> working because: "QML Rectangle: Cannot anchor to an item that isn't a
>> parent or sibling." so i'm stuck getting that to work. You can also
>> see this by running the code in the paste.kde.org link and the
>> main.qml. Once running just click and drag anywhere,
>>
>> also, if i change the line: console.log(item) (line 251) to
>> console.log(item.id) it prints "undefined" while the id is in fact set
>> in the actual elements.. Does anyone know why this is the case? I
>> would expect it to return the id.
>>
>> Another side issues that i also have is the flickable area.. I want my
>> "custom" mousearea to catch the clicked and pressed events, the rest
>> can be passed on to Flickable, but how do i do that?
>>
>> I hope someone can provide me some pointes on how to fix these issues.
>> Perhaps i'm doing ot all wrong and there might even be a lot easier
>> way that i don't know yet.
>>
>> Kind regards,
>> Mark
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>
>
> Bo Thorsen,
> Fionia Software.
>
> --
>
> Expert Qt and C++ developer for hire
> Contact me if you need expert Qt help
> http://www.fioniasoftware.dk
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

Just a FYI. I have tried the possible suggestion and failed using that
technique (so preventing a repeater). So i went back to the code
posted in here and took a whole different approach. What i'm doing now
is simply taking the given mouse positions, do some calculations on
that and end up with a new X an Y position where i want my overlay to
be placed. Once i have that i simply put the element i want at those
positions and that does seem to work fine.

The only code change for that compared to the one on the paste link is
the onPositionChanged in the Mousearea:

            onPositionChanged:
            {
                var rootItem = contentList.childAt(mouseX, mouseY)
                if(rootItem === null)
                {
                    return
                }

                var tempY = mouseY % rootItem.height
                var tempX = mouseX % rootItem.width
                var item = rootItem.childAt(tempX, tempY)

                if(item === null)
                {
                    return
                }

                if(item.height === 13)
                {
                    var newXPos = parent.x
                    var newYPos = (mouseY - tempY) + (item.y - item.height) + 13
                    rowSelection.x = newXPos + root.leftTextOffset
                    rowSelection.y = newYPos
                }
            }

This feels very hacky and even wrong to do.. but it works, so i guess
i just continue with this.



More information about the Interest mailing list