Results 1 to 8 of 8

Thread: Q_PROPERTY with binding to designer

  1. #1
    Join Date
    Apr 2016
    Location
    Ravensburg, Germany
    Posts
    4
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Q_PROPERTY with binding to designer

    Hello to all:-)

    I have a question about the Q_PROPERTY macro.
    In Qt-documentation
    (http://doc.qt.io/qt-4.8/http://doc.qt.io/qt-4.8/properties.html#requirements-for-declaring-properties),
    they tell about the "DISIGNABLE"-attribute:

    The DESIGNABLE attribute indicates whether the property should be visible in the property editor of GUI design tool (e.g., Qt Designer). Most properties are DESIGNABLE (default true). Instead of true or false, you can specify a boolean member function.
    Now, i simply built a small test-widget with a label and a Pushbutton. In the code, i have a QString-property "smallText"

    .h-file
    Qt Code:
    1. namespace Ui {
    2. class MainWindow;
    3. }
    4.  
    5. class MainWindow : public QMainWindow
    6. {
    7. Q_OBJECT
    8. Q_PROPERTY(QString smallText READ smallText WRITE setSmallText NOTIFY smallTextChanged)
    9.  
    10. public:
    11. explicit MainWindow(QWidget *parent = 0);
    12. ~MainWindow();
    13.  
    14. QString smallText() const
    15. {
    16. return m_smallText;
    17. }
    18.  
    19. public slots:
    20. void setSmallText(QString smallText);
    21. {
    22. if (m_smallText == smallText)
    23. return;
    24.  
    25. m_smallText = smallText;
    26. emit smallTextChanged(smallText);
    27. }
    28. signals:
    29. void smallTextChanged(QString smallText);
    30.  
    31. private slots:
    32. void on_pushButton_clicked();
    33.  
    34. private:
    35. Ui::MainWindow *ui;
    36. QString m_smallText;
    37. };
    To copy to clipboard, switch view to plain text mode 

    when i click on the Pushbutton, the Property "smallText" is changed, but where can I tell the label to change?
    Of course, I could move the definition of "setSmallText" to the *.cpp-file and add
    Qt Code:
    1. ui->label->setText(smallText);
    To copy to clipboard, switch view to plain text mode 
    , but is there any possibility to use the the "DESIGNABLE"-attribute?

    I unfortunately have to use Qt4.5.2 with Qt-Creator
    Thanks for any help
    Robby

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Q_PROPERTY with binding to designer

    If you want "ui->label" to change when smallText is changed, simply connect smallTextChanged() to the label's setText() slot.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Big_Stone88 (15th April 2016)

  4. #3
    Join Date
    Apr 2016
    Location
    Ravensburg, Germany
    Posts
    4
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Q_PROPERTY with binding to designer

    Thanks for your answer

    Yeah.....

    sure, that would be a simple solution...
    But what is the function of the mentioned "DISIGNABLE"-attribute then?

    Robby

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Q_PROPERTY with binding to designer

    As the documentation says: properties that are marked as designable (most of them), will be displayed in the QtDesigner's property editor.

    Cheers,
    _

  6. #5
    Join Date
    Apr 2016
    Location
    Ravensburg, Germany
    Posts
    4
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Q_PROPERTY with binding to designer

    What the documentation doesn't give away:
    WHERE will it be displayed in the QtDesigner's property editor?

    Robby

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Q_PROPERTY with binding to designer

    I am not sure what you mean.

    The property editor iterates over the properties and displays them grouped by the class they are declared in, starting with QObject, ending with the actual class itself.

    E.g. if you look at the properties of a QPushButton, the first section has the properties of QObject, then QWidget, then QAbstractButton, then QPushButton.

    So if you derive from QPushButton and add another property, it will be in its own section, following the QPushButton section.

    Cheers,
    _

  8. #7
    Join Date
    Apr 2016
    Location
    Ravensburg, Germany
    Posts
    4
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Q_PROPERTY with binding to designer

    That's exactly my problem:
    My ui is a
    Qt Code:
    1. mainWindow : QMainWindow
    To copy to clipboard, switch view to plain text mode 
    when I select the mainWindow in the object-tree, there are only three categories in the property editor: QObject, QWidget and QMainWindow. There is no Category as the name of my class "mainWindow" (see following pic).
    PropertyEditor.PNG
    even if I build two new classes (Form1 : QWidget AND Form2 : Form1) and i set a Q_Property with the name smallText in Form1, i see in the property-editor of "Form2" neither a category "Form1" nor a property "smallText" in any other category.

    What am i doing wrong?
    Thanks for your help

    Robby

  9. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Q_PROPERTY with binding to designer

    Quote Originally Posted by Big_Stone88 View Post
    That's exactly my problem:
    My ui is a
    Qt Code:
    1. mainWindow : QMainWindow
    To copy to clipboard, switch view to plain text mode 
    when I select the mainWindow in the object-tree, there are only three categories in the property editor: QObject, QWidget and QMainWindow. There is no Category as the name of my class "mainWindow" (see following pic).
    The type is QMainWindow, as you can see in the second column in the object tree view.


    Quote Originally Posted by Big_Stone88 View Post
    even if I build two new classes (Form1 : QWidget AND Form2 : Form1) and i set a Q_Property with the name smallText in Form1, i see in the property-editor of "Form2" neither a category "Form1" nor a property "smallText" in any other category.
    Does the designer plugin that provides "Form1" create instances of Form1 or maybe just QWidget?
    Does Form1 have the Q_OBJECT macro additional to the Q_PROPERTY macro?

    Cheers,
    _

Similar Threads

  1. Q_property
    By Ini in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2016, 08:39
  2. Pointer in Q_PROPERTY
    By pkorzeniewski in forum Qt Programming
    Replies: 3
    Last Post: 20th September 2012, 09:32
  3. Q_property
    By micky in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2012, 18:51
  4. Why and when to use Q_PROPERTY
    By Vanir in forum Qt Programming
    Replies: 4
    Last Post: 22nd November 2007, 09:25
  5. How to Use Q_PROPERTY
    By mitesh_modi in forum Qt Programming
    Replies: 7
    Last Post: 20th June 2006, 14:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.