[solved] TextFieldStyle: Height of Rectangle does not correspond font size...



  • I have a TextField and want to give it a custom style:

    @
    TextField
    {
    id: blah;
    anchors { left: test.right; top: test.top; }
    font { family: "Arial"; pointSize: 14; }
    style: TextFieldStyle
    {
    textColor: "#000";
    background: Rectangle
    {
    color: "#FFF";
    border.color: "#999";
    border.width: 1;
    radius: 4
    // implicitHeight: 100;
    // implicitHeight: blah.height;
    }
    }
    }
    @

    The Rectangle is supposed to be as large as the text in the TextField. However, this is not the case: The rectangle is apparently given a constant height, ignoring whatever font size is set in the TextField.

    If I set implicitHeight to some constant value, this'll work, but it obviously isn't what I'm looking for. If I set implicitHeight to the TextField's height, nothing happens (except that I saw an error complaining about anchor loop once.)

    How do you do this correctly?


  • Moderators

    Hi,

    Above example works for me. Tested on Qt 5.3.1, Ubuntu 14.04
    @
    Rectangle {
    width: 300
    height: 300

    TextField
    {
        id: blah;
        font { family: "Arial"; pointSize: 32; }
        style: TextFieldStyle
        {
        textColor: "#000";
        background: Rectangle
        {
        color: "#FFF";
        border.color: "#999";
        border.width: 1;
        radius: 4
    }
    

    }
    }
    @



  • Strange... I'm testing this on Windows and on Android, and it doesn't work on either platform! Qt 5.3.0


  • Moderators

    Can you try with Qt 5.3.1 ?



  • I'll check this as soon as I find the time. In the meantime, did you use these components:

    @
    import QtQuick.Controls 1.2
    import QtQuick.Controls.Styles 1.2
    @

    Or some newer version?


  • Moderators

    Yes
    @
    import QtQuick 2.3
    import QtQuick.Controls 1.2
    import QtQuick.Controls.Styles 1.2
    @

    Also worked with
    @
    import QtQuick 2.0
    @



  • I've downloaded Qt 5.3.2, now the problem is gone!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.