Important: Please read the Qt Code of Conduct -

Qt custom widgets propertis are not getting updated properly in Qt designer

  • I have created a custom widget.
    The widget gets loaded fine,the properties appear in QT Designer,
    Only problem is every time I change the property of Alpha key,the
    numeric also gets set,
    Though the accessor functions are different,and the enums are differnet
    and values are different.
    Also whenever i check the Form->view code,the values would have got
    Am i Missing something or this is a designer issue,Any workarounds
    would be appreciated

    class key
    Q_PROPERTY(AlphKeycode_t AlphKeycode READ AlphKeycode WRITE
    Q_PROPERTY(bool AlphKey READ isAlph WRITE setAlph);

    Q_PROPERTY(NumKeycode_t NumKeycode READ NumeKeycode WRITE
    Q_PROPERTY(bool NumKey READ isNum WRITE setNum);

    AlphKeycode_t m_AlphaKeycode;
    NumKeycode_t m_NumKeycode

    key::key(QWidget *parent) :


    connect(this, SIGNAL(clicked()), this, SLOT(KeyClicked()));

    struct AlphData
    QString label;
    bool isAlphabetic;

    struct NumData
    QString label;
    bool isNumeric;

    AlphData AlphKeyData[] =
    {"q",true },
    NumData NumKeyData[] =
    {"1", false},

    bool key::isAlphabetic()
    return AlphKeyData[m_AlphabeticKeycode].isAlphabetic;
    void key::setAlphabetic(bool arg)
    AlphKeyData[m_AlphaKeycode].isAlphabetic = arg;

    bool key::isNumeric()
    return NumKeyData[m_NumKeycode].isNumeric;

    void key::setNumeric(bool arg)
    NumKeyData[m_NumKeycode].isNumeric = arg;

    //Slot Function
    void key::KeyClicked()
    if (AlphKeyData[m_AlphaKeycode].isAlphabetic)
    Q_EMIT this->OnDataKeyClicked(m_AlphaKeycode);
    if (NumKeyData[m_NumKeycode].isNumeric)
    Q_EMIT this->OnDataKeyClicked(m_NumKeycode);

    [EDIT: added @-tags for code formatting, Volker]

  • Please use proper code format. And which version of Qt Creator are you testing your properties, maybe can be a Creator bug

  • Your code does not show the relevant methods for handling the properties' getters and setters. It's hard to know what's going wrong there.

  • Thanks for the replies,Sorry for code formatting.

    I am using Qt designer 4.7 on linux,The plugin is built on linux using C++code,with the usual MOC'ing and It generates ui_key.h
    What Iam feeling is every time i create a new instance,The property editor does not start with a fresh set of default values. Some how it retains some old values,
    I want to get something like
    is Numeric
    These should be unigue for a key,which means if i choose alpha,and set is alpha ,it should retain this property.
    On creating a new key ,the property sheet still imagines that i need to create a alpha key and shows the isAlpha enabled.
    so when i choose numeric,it sets the key to be true for both alpha and numeric using qVariant.
    ,hence the slot function goes for a toss.

    I have not used any qvariant in code.Iam not aware how to disable this qvariant.
    Also I would like the AlphaKey and NumericKey to be exclusive. Which means,If I create a alphakey and set it to alpha,next time I want to create Numeric,The property sheet should start fresh with all default values,and on setting it as numeric,It should just set it as numeric.
    Any ideas will be very helpful

  • AlphData AlphKeyData[] is a regular C/C++ array and thus 0-based. You cannot access it with the character stored in it. Depending on the compiler and other circumstances you will cause a crash of your program.



    you access the array at index 81 or 113 ('Q' or 'q').

    Apart from that, I do not understand what you want to do.

Log in to reply