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] IntValidator does not check range correctly after assignment of min/max range from delegate

[SOLVED] IntValidator does not check range correctly after assignment of min/max range from delegate

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.1k Views
  • 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
    serdef
    wrote on 5 Jun 2014, 09:50 last edited by
    #1

    Hello,

    IntValidator behaves strangely when I assign the limits through a delegate :
    The value from the model data appears, and I can edit that, but the range is not checked :

    • I can enter 8888888888888888888 when range is set to -100,+100.
    • when i delete all characters, i can no longer type new digits into the field.

    If this same assignment is executed in a separate test, Testscreen1.qml, a simple button onclick handler,
    this works fine, I don't see why this works and the other situation not.
    When I look with the qml 'live' debug object viewer, the assignments seem to be ok.
    In the c++ objects from the qlist in the mode, the properties are QStrings :
    Q_PROPERTY(QString prop_min READ getmin WRITE setmin NOTIFY minChanged)
    Q_PROPERTY(QString prop_max READ getmax WRITE setmax NOTIFY maxChanged)

    (I use string properties as this may later be extended to a hex range as well).

    So I would be very happy if an expert here can see what I am doing wrong (be it a bug or the wrong way).

    Thank you,
    Serge

    @

    // code from delegate, this causes the problem :

    id: paramlijstDelegate
    Row {
    id: paramlijst
    Rectangle {
    width: 250
    height: 60
    color: "#353535"
    radius : 5
    MouseArea{
    id: paramlistMouseArea
    anchors.fill: parent
    onClicked: {
    paramedit1.paramname = model.modelData.prop_name;
    paramedit1.paramdescription = model.modelData.prop_description;
    paramedit1.paramvalue = model.modelData.prop_value;
    paramedit1.parammax = model.modelData.prop_max;
    paramedit1.parammin = model.modelData.prop_min;
    }
    }
    Column {
    width: parent.width
    anchors.horizontalCenter: parent.horizontalCenter
    Text { width: parent.width; anchors.horizontalCenter: parent.horizontalCenter; font.pointSize : 18 ; horizontalAlignment:Text.AlignHCenter; text : model.modelData.prop_name; color: "#00B4FF" }
    Text { width: parent.width; anchors.horizontalCenter: parent.horizontalCenter; font.pointSize : 14 ; horizontalAlignment:Text.AlignHCenter; text: model.modelData.prop_value; color: "#FFFFFF" }
    }
    }

    @

    @
    // code from Testscreen1.qml, this does work fine
    Button {
    id: udpateparam_button
    x: 50
    y: 325
    width: 50
    text: qsTr("Assign Data")
    onClicked: {
    paramedit.paramname = "updatedparam";
    paramedit.paramdescription = "description";
    paramedit.paramvalue = "20";
    paramedit.parammax = "99";
    paramedit.parammin = "-99";
    }
    }

    @
    @
    //ParamEdit.qml

    import QtQuick 2.2
    import QtQuick.Dialogs 1.1
    import QtGraphicalEffects 1.0
    import QtQuick.Controls 1.2
    import QtQuick.Controls.Styles 1.2
    import "controls"
    import "."
    Item {

    property string paramname :"paramname" 
    property string paramvalue :"500" 
    property string parammin : "-999" 
    property string parammax : "999" 
    property string paramdescription : "no description" 
    Text {
        id: paramnamelabel
        x: 25
        y: 15
        color : "#00B4FF" 
        text:  paramname
        font.pixelSize: 24
    }
    TNumericEditV1{
        id: paramvalueedit
        x: 25
        y: 55
        width: 80
        height: 35
        text: paramvalue
        minimum : parseInt(parammin)
        maximum : parseInt(parammax)
        font.pixelSize: 18
    }
    Text {
        id: paramdescriptionlabel
        x: 25
        y: 100
        text:  paramdescription
        color : "#B3B3B3" 
        font.pixelSize: 12
    }
    Button {
        id: button_apply_field
        x: 25
        y: 300
        text: qsTr("Apply")
        onClicked : marpguiobj1.setParameterValue(paramnamelabel.text,paramvalueedit.text);
    }
    

    }

    //TNumericEditV1.qml
    import QtQuick 2.2

    Rectangle {
    width: 96; height: input.height + 8
    color: "lightsteelblue"
    border.color: "gray"
    property alias text: input.text
    property alias input: input
    property alias font : input.font
    property int minimum : 0
    property int maximum : 1000

    TextInput {
        id: input
        anchors.fill: parent
        anchors.margins: 4
        focus: true
        validator: IntValidator { bottom:minimum; top: maximum}
        inputMethodHints : Qt.ImhFormattedNumbersOnly
    }
    

    }
    @

    1 Reply Last reply
    0
    • S Offline
      S Offline
      serdef
      wrote on 5 Jun 2014, 12:14 last edited by
      #2

      Solved, the above code was OK !
      My test model data was wrong : It had minimum and maximum swapped (min =100, max = -100).
      Doh!

      This had the effect that I could edit the existing value (that was out of range) without limits, but after deleting all characters i could not enter anything.

      Oh well, above code may be useful to someone, it works fine when fed with the correct parameters ;-).

      1 Reply Last reply
      0

      2/2

      5 Jun 2014, 12:14

      • Login

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