Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30

Thread: Custom Property On Custom Widget

  1. #21
    Join Date
    Jun 2012
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Property On Custom Widget

    ...makes Qt Designer crash.
    What kind of crash exactly? Do you get a stack strace, exception message or anything like that?

  2. #22
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    2

    Default Re: Custom Property On Custom Widget

    Quote Originally Posted by ViRuSTriNiTy View Post
    What kind of crash exactly? Do you get a stack strace, exception message or anything like that?
    I've just found the cause of the problem. I did not guard against recursive calls to createExtension(). I've just done so however and I no longer get crashes, although I used a static variable like so

    Qt Code:
    1. QObject* CustomWidgetFactory::createExtension(QObject *object, const QString &iid, QObject* parent ) const
    2. {
    3. static bool extensionSheetIsInitialized = false;
    4.  
    5. if( !extensionSheetIsInitialized )
    6. {
    7. extensionSheetIsInitialized = true;
    8. ...
    9. }
    10.  
    11. return 0;
    12. }
    To copy to clipboard, switch view to plain text mode 

    There is now the larger issue of how to proceed. How do I assign my indexes to my widget properties? So that I can control whether they are shown in the the properties editor? Ideally what I'd like to do is to display a subset of relevant properties of the widget depending on the value of a master property. For example, the master property could represent the shape of the wigdet while the remaining properties could include radius (for circles), length for squared etc, where the radius property is displayed only of the mater property is set to circle.

  3. #23
    Join Date
    Jun 2012
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Property On Custom Widget

    Quote Originally Posted by Olumide View Post
    I've just found the cause of the problem. I did not guard against recursive calls to createExtension()
    Yep, thats why i added the red comment to mCreateExtensionCalled, back then i stumble upon this recursion too.

    Quote Originally Posted by Olumide View Post
    How do I assign my indexes to my widget properties? So that I can control whether they are shown in the the properties editor? Ideally what I'd like to do is to display a subset of relevant properties of the widget depending on the value of a master property. For example, the master property could represent the shape of the wigdet while the remaining properties could include radius (for circles), length for squared etc, where the radius property is displayed only of the mater property is set to circle.
    The only solution i had found was to use a "index"-"property name" map. With that in mind i would suggest you

    1) enumerate all properties of your widget in the constructor of the property sheet class
    2) remember those properties in the "index"-"property name" map
    3) override each virtual function of the property sheet and return the appropriate property values by using the "index"-"property name" map

    I'm sorry that i cannot post any additional code because it's lost. But i closely remember what i was doing back then.

  4. #24
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    2

    Default Re: Custom Property On Custom Widget

    Quote Originally Posted by ViRuSTriNiTy View Post
    The only solution i had found was to use a "index"-"property name" map. With that in mind i would suggest you

    1) enumerate all properties of your widget in the constructor of the property sheet class
    2) remember those properties in the "index"-"property name" map
    3) override each virtual function of the property sheet and return the appropriate property values by using the "index"-"property name" map

    I'm sorry that i cannot post any additional code because it's lost. But i closely remember what i was doing back then.
    Thanks for your reply.

    Unfortunately, I'm getting really confused. First, I have difficulty understanding the the way indexes are assigned by Qt Designer to properties. Surely custom properties have indexes even if a custom property sheet does not exist. So does a custom property sheet prevent Qt Designer from assigning a property to a custom property? And what index ranges should be assigned to custom properties? From 0 (as Santosh Reddy suggests) or from mpDefaultPropertySheetExtension.count() , as you suggest? Also custom properties display the correct names given to them when declared with Q_PROPERTY(). What then is the purpose of QDesignerPropertySheetExtension::propertyName()?

    What's more confusing is that nothing I do in my custom property sheet extension appears to show up in Qt Designer, even an exit() call or QCoreApplication::exit() does nothing. Furthermore without the use of a debugger I can't be absolutely sure that qt_extension<> returns a non-NULL default property sheet and that my custom property sheet is instantiated.

    Very confused.

    :(

  5. #25
    Join Date
    Jun 2012
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Property On Custom Widget

    Quote Originally Posted by Olumide View Post
    Thanks for your reply.

    Unfortunately, I'm getting really confused.
    Dont be sad, being confused is a normal reaction to this stuff as almost no example code exists. I had to solve almost everything on my own by building a debug version of Qt and debugging the inner core of Qt to get this custom property stuff working. This was a hell of a nightmare as in the end only version 4.7.0 and 4.8.2 compiled successfully without showing Qt crashes later on.

    Quote Originally Posted by Olumide View Post
    First, I have difficulty understanding the the way indexes are assigned by Qt Designer to properties. Surely custom properties have indexes even if a custom property sheet does not exist.
    As far as i remember: the Qt designer uses the custom property sheet if defined. A custom property sheet overrides the complete property list displayed in the designer. Since you are enumerating all properties in the constructor of the property sheet class, you can implement count() like so:

    Qt Code:
    1. ... ::count ()
    2. {
    3. return mpIndexPropertyNameMap.size();
    4. }
    To copy to clipboard, switch view to plain text mode 

    The Qt designer will then execute a index loop from 0 to count() - 1 and call additional methods like propertyName(), isVisible() and so on to display the properties accordingly in the property editor.

    Quote Originally Posted by Olumide View Post
    What's more confusing is that nothing I do in my custom property sheet extension appears to show up in Qt Designer, even an exit() call or QCoreApplication::exit() does nothing. Furthermore without the use of a debugger I can't be absolutely sure that qt_extension<> returns a non-NULL default property sheet and that my custom property sheet is instantiated.
    This is what i was referring to in the first comment of this post. After hours of trying to solve this via trail and error with exit() or writing log text files i compiled Qt as debug build. But you don't really have to go that hellish route, just try to write out a log file first. This should be a quite easy task.

  6. #26
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    2

    Default Re: Custom Property On Custom Widget

    Thanks.

    I'm going to try logging for a start. Its really strange that exit() doesn't work yet leaving out the boolean variable/guard causes the application to call the QExtensionFactory::createExtension() recursively.

    In the interim I've setting a property as DESIGNABLE with a boolean member function as a value instead of true or false. But this causes the property to be grayed out and not hidden.

    BTW, what do you think of this recommendation? Trouble is that I'm not quite sure which class does this? QDesignerCustomWidgetInterface perhaps?

  7. #27
    Join Date
    Jun 2012
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Property On Custom Widget

    Quote Originally Posted by Olumide View Post
    Its really strange that exit() doesn't work yet leaving out the boolean variable/guard causes the application to call the QExtensionFactory::createExtension() recursively.
    This has something to do with the internals of Qt, you could see why it doesn't work when using a debug version of Qt. I cannot remember what it was exactly but i had the same problem too, then i changed to logging via text files.

    Quote Originally Posted by Olumide View Post
    I've setting a property as DESIGNABLE with a boolean member function as a value instead of true or false. But this causes the property to be grayed out and not hidden.
    Hehe, i had the same issue too. As far as i remember the designable thing is a bit buggy, just skip it if you don't really need it. If you need a read only property in the property editor then use QDesignerPropertySheetExtension::isVisible(), there's a reason why it exists

    Quote Originally Posted by Olumide View Post
    BTW, what do you think of this recommendation?
    Yes, this is the way to make properties a bit more dynamic. You should keep in mind that the Qt designer buffers many values returned by QDesignerPropertySheetExtension (i cannot recall which ones exactly), it's done when Qt designer starts. I used this approach to dynamically hide / show properties by using a context menu.

    Quote Originally Posted by Olumide View Post
    Trouble is that I'm not quite sure which class does this? QDesignerCustomWidgetInterface perhaps?
    Depends on what you want to achieve. As i stated above, for me it was the click handler of the context menu that executed this code. Just place it where you need it as it's based on a static function.

  8. #28
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    2

    Default Re: Custom Property On Custom Widget

    Logging to a text file is surprisingly instructive. 'Shows that for some strange strange reason QExtensionFactory::createExtension() is called for QCheckBox only!???

  9. #29
    Join Date
    Jun 2012
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Property On Custom Widget

    @Olumide

    Hmm strange. You should upload your complete source code somewhere so i can have a look at it.

  10. #30
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    2

    Default Re: Custom Property On Custom Widget

    Quote Originally Posted by ViRuSTriNiTy View Post
    Hmm strange. You should upload your complete source code somewhere so i can have a look at it.
    That was bug/typo. Its now working properly, although I had to create the property extension on the parent extension and not on the widget itself, as shown below:

    Qt Code:
    1. QDesignerPropertySheetExtension* defaultPropertySheetExtension = qt_extension<QDesignerPropertySheetExtension*>( m_extensionManager , parent );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Custom property in designer
    By avgust in forum Newbie
    Replies: 1
    Last Post: 9th September 2010, 10:14
  2. File dialog for custom widget property?
    By TheJim01 in forum Newbie
    Replies: 1
    Last Post: 6th May 2010, 10:14
  3. Animatin a custom property
    By Luc4 in forum Qt Programming
    Replies: 2
    Last Post: 13th April 2010, 08:37
  4. Replies: 4
    Last Post: 5th March 2010, 14:20
  5. Replies: 5
    Last Post: 16th May 2006, 20:38

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.