Qt-jambi-interest Archive, October 2007
Designable properties / custom widgets
Message 1 in thread
Hi all!
I'm playing around with a custom widget and trying hard to get the custom
properties exposed in the designer.
Now, I probably miss something, but as far as I understand from the
documentation, Qt would be able to automatically detect properties and their
getters/setters by identifying the method names using Java reflection
classes, right? I've set the QtPropertyDesignable annotation on the getter
method to be sure. I've also tried setting the QtPropertyReader and -Writer
to be sure even more so ;) - Unfortunately, the property refuses to show up
in the designer. Is there something I'm missing?
Btw, the property does show up when enumerating using the QtPropertyManager.
Kind regards,
Sander v.d. Merwe
Message 2 in thread
S. van de Merwe wrote:
> properties exposed in the designer.
>
> Now, I probably miss something, but as far as I understand from the
> documentation, Qt would be able to automatically detect properties and their
> getters/setters by identifying the method names using Java reflection
> classes, right? I've set the QtPropertyDesignable annotation on the getter
> method to be sure. I've also tried setting the QtPropertyReader and -Writer
> to be sure even more so ;) - Unfortunately, the property refuses to show up
> in the designer. Is there something I'm missing?
>
Hi!
Properties are recognized by annotating accessor methods for them. The
basic annotations you need to worry about are QtPropertyReader and
QtPropertyWriter.
int fooBar;
@com.trolltech.qt.QtPropertyReader(name="fooBar")
public int fooBar() { return fooBar; }
@com.trolltech.qt.QtPropertyWriter(name="fooBar")
public void setFooBar(int fooBar) { this.fooBar = fooBar; }
The QtPropertyDesignable is only necessary if you wish to restrict
Designer from seeing the properties, since all properties are designable
by default.
A few things to consider here, which may go wrong:
1. The name of the property is given as a parameter to the annotation
(name="...") and needs to be identical for both the reader and writer.
The method names can be anything you choose. Naturally, the methods can
perform whatever actions you please, the code in the example above is
just intended for illustration.
2. The return value of the reader and the input value of the writer need
to match.
3. The reader should take no arguments and the writer should take one.
The writer should not return a value.
4. You need to be running Qt Jambi Designer (designer.bat/designer.sh in
the binary package.) This can be verified by checking that the property
editor or signals/slots editor show Java syntax in the signatures for
enums and methods.
5. Your widget needs to be exposed as a custom widget to Designer, so
that it appears in the widget box.
6. The accessor methods should be public, as should the class itself.
If you do all this, and then drop an instance of your widget into a
form, then you should find your custom property at the very bottom of
the property editor when you've selected the widget. If this fails, then
I am unable to reproduce the problem without some further information:
First of all, what is the type of your property? It may be a type not
familiar to Designer, in which case it will be ignored.
Secondly, could you attempt pasting the example code above into one of
the Qt Jambi examples, such as the com.trolltech.examples.CollidingMice
class? This should be available as a custom widget in Designer by
default, and if you add the code above, recompile and drop it into a
form in Designer, you should see the fooBar property in the property editor.
-- Eskil