4

When I use TumblerColumn in my Tumbler, I get QML QQuickText: Cannot anchor to an item that isn't a parent or sibling, When I use Tumbler alone the error doesn't appear. I can't figure out what is the problem with TumblerColumn.

Here is my Dialog code

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Extras 1.2

Dialog {
    id: customTimerInputDialog
    title: "Custom timer"
    height: 150
    width: 300
    standardButtons: StandardButton.Ok | StandardButton.Cancel
    onAccepted: {

    }

    onRejected: {
        console.log("Rejected")
    }

    Column {
        anchors.fill: parent
        Text {
            text: "Timer"
            height: 40
        }

        Tumbler {
            id: tumbler
            TumblerColumn {
                model: 10
            }

            TumblerColumn {
                model: 60
            }
        }
    }
}

TumblerColumn (TumblerStyle.qml) complete source code

...
// line 294
property Component delegate: Item {
    implicitHeight: (control.height - padding.top - padding.bottom) / tumblerStyle.visibleItemCount

    Text {
        id: label
        text: styleData.value
        color: "#666666"
        opacity: 0.4 + Math.max(0, 1 - Math.abs(styleData.displacement)) * 0.6
        font.pixelSize: Math.round(TextSingleton.font.pixelSize * 1.25)
        anchors.centerIn: parent
    }
}
...

Error message enter image description here

UPDATE

I get the same error with Popup QML Type

Popup {
    id: popup
    x: 100
    y: 100
    width: 200
    height: 300
    modal: true
    focus: true
    closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent

    Tumbler {
        id: intervalPicker
        TumblerColumn {
            model: 10
        }

        TumblerColumn {
            model: 60
        }
    }
}
Junius L
  • 15,881
  • 6
  • 52
  • 96

1 Answers1

-1

You are mixing Qt Quick Controls 1 and 2. In your Dialog/Popup you import QtQuick.Controls 2.2 and QtQuick.Extras 1.2. Both imports define a Tumbler, but the one from Qt Quick Extras is made to work with Qt Quick Controls 1 (see the imports in TumblerStyle.qml).

If you want to use TumblerColumn and TumblerStyle, you have to use the Tumbler from Qt Quick Extras 1.2.

If you want to use the Tumbler from Qt Quick Controls 2, you cannot use any of the tumbler facility from Qt Quick Extras 1.2.

If you need to have both Qt Quick Extras 1.2 and Qt Quick Controls 2 imported in a qml file, you need to use the as qualifier:

import QtQuick.Extras 1.2 as Extra
import QtQuick.Controls 2.2 as Controls2

...
Extra.Tumbler 
{
...
}

Controls2.Tumbler 
{
...
}
...
Benjamin T
  • 8,120
  • 20
  • 37