Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt custom widgets propertis are not getting updated properly in Qt designer
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.3k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    lepepper
    wrote on last edited by
    #1

    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
    modified.
    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
    setAlphKeycode);
    Q_PROPERTY(bool AlphKey READ isAlph WRITE setAlph);
    Q_ENUMS(AlphKeycode_t);

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

    private:
    AlphKeycode_t m_AlphaKeycode;
    NumKeycode_t m_NumKeycode

    }
    key::key(QWidget *parent) :
    QPushButton(parent),

    m_AlphaKeycode(e_Keycode_Q),
    m_NumKeycode(e_Keycode_1),
    AlphaKey(false),
    NumericKey(false)

    {
    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]

    1 Reply Last reply
    0
    • M Offline
      M Offline
      milot.shala
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        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.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lepepper
          wrote on last edited by
          #4

          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
          AlphaKey
          isAlpha
          NumKey
          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

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            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.

            In

            @
            AlphKeyData[m_AlphabeticKeycode]
            @

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

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

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0

            • Login

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