You are not logged in.

hatulflezet

Professional

  • "hatulflezet" started this thread

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

1

Thursday, June 3rd 2004, 7:06pm

"value list" for custom widgets properties

Hi All,

I created a custom widget, which has one property that is an enum value.
I would like to let the user select a value out of a "string" list for this property.
Similar to "mouseTracking" property where the user can choose between "true" and "false" from a combobox.
However, when adding a custom widget to QtDesigner, the only "similar" thing that I can do, is declare a property of type "int" (this way the user can enter an int corresponding to the enum he needs - but for that he needs to know the enum values... not practical).
Is it possible to have a "string" list that corresponds to the enum values in my custom widgets H file - or will it be only possible with a plugin - and then - how do I make the plugin load these values?
I read the docs about custom widgets and properties and plugins, none dealt with this issue (thats I could find)...

Any pointers will be nice!


Thanks
Dani.
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

2

Thursday, June 3rd 2004, 9:14pm

RE: "value list" for custom widgets properties

In your mywidget.h:

Source code

1
2
3
4
Q_ENUMS( MyEnum )

Q_PROPERTY( MyEnum myProp READ myProp WRITE setMyProp
                             DESIGNABLE true SCRIPTABLE true STORED true )


DESIGNABLE is interesting when we want the widget usable in designer.
SCRIPTABLE allows QSA interaction
STORED allows for property serailization when storing the widget.

If the widget has to be used in designer, the class must be declared as:
class QT_WIDGET_PLUGIN_EXPORT MyWidget : public QWidget

Read Creating Custom Widgets in Assistant Help, section Designer.
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

hatulflezet

Professional

  • "hatulflezet" started this thread

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

3

Friday, June 4th 2004, 8:48am

RE: "value list" for custom widgets properties

Thanks for the answer
As I said, I have read the docs on creating custom widgets.
The only thing that it said there about the SCRIPTABLE parameter is:

SCRIPTABLE declares whether this property is suited for access by a scripting engine. The default is TRUE. Instead of TRUE or FALSE, you can specify a boolean member function.

I was not sure what the scripting options offered and it didn't say eather...:-(

From your answer I got it that this means I need to use QSA (somthing I was not aware existed).
Is that correct?
And if so, then does this means that a custom widget will be able to have predefined values for the properties only as a plugin and not as a simple custom widget, since as far as I can understand, the script needs to be run by an application (i.e plugin is a binary so I guess you can say an "application")?

I am trying to look for more info on this - but I must say, its not that easy to find, such as other subjects in QT...(The QSA documentation it self is rather thin too) if any one here has some experiance with doing this, links, code snipets or a general explanations will be most welcome.

Thanks!.
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

4

Friday, June 4th 2004, 10:55am

RE: "value list" for custom widgets properties

Quoted


I was not sure what the scripting options offered and it didn't say eather...:-(

From your answer I got it that this means I need to use QSA (somthing I was not aware existed).


About QSA, have a look at Qt Script for Applications. You can eventually use other scripting engines too.

Is that correct?

The SCRIPTABLE option for properties only tell if the property can be accessed by scripting engines, and nothing else.

Quoted


And if so, then does this means that a custom widget will be able to have predefined values for the properties only as a plugin and not as a simple custom widget, since as far as I can understand, the script needs to be run by an application (i.e plugin is a binary so I guess you can say an "application")?

The property is always available, as properties are defined in QObject and QMetaObject classes. Thus, you can define properties not available to Designer, nor scriptable, but accessible by name with standard getter and setter methods or introspected using the property() and setProperty() methods.

Properties just act as standard methods. The getter is a public method with the const attribute and the setter must be a public slot.

Quoted


I am trying to look for more info on this - but I must say, its not that easy to find, such as other subjects in QT...(The QSA documentation it self is rather thin too) if any one here has some experiance with doing this, links, code snipets or a general explanations will be most welcome.

QSA documentation is nice and comprehensive. You should have a look to the samples in the qsa examples directory. They'll give you more than simple snippets.
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

hatulflezet

Professional

  • "hatulflezet" started this thread

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

5

Friday, June 4th 2004, 12:05pm

Hi,

I guess I am not being clear enough... I'll try to explain my self again...
My problem is not adding a property to a custom widget.
I HAVE added the properties I want, and they are being set nicely by the get and set functions too, with the values given in the property dialog in designer, and through code.
What I am interested in, is, having fixed input values the user can choose from for these properties at deign time (i.e like backgroundOringin property that most widgets have) .

Is that done with scripting?

If so, can it be done with a simple widget which is not a plugin?

If someone had done that, an explenation on how to go about it would be nice (like a list of steps) - code is not a must - but would be nice ;-)
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

6

Friday, June 4th 2004, 12:22pm

Quoted

What I am interested in, is, having fixed input values the user can choose from for these properties at deign time (i.e like backgroundOringin property that most widgets have) .

backgroundOrigin is a Q_ENUM() style. You set it usng the enum as property type.
The user can only use values in the fixed values proposed.

Quoted

Is that done with scripting?

No need for scripting there. All QVariant types are allowed as property type. This gives some latitude.

Quoted


If so, can it be done with a simple widget which is not a plugin?

If someone had done that, an explenation on how to go about it would be nice (like a list of steps) - code is not a must - but would be nice ;-)

If the setup is allowed in your program, the widget does not have to be declared as a plugin. But if you want to allow one to parametrize the widget from designer, you include the qwidgetplugin.h header and add QT_WIDGET_PLUGIN_EXPORT in class
declaration.
Declaring a widget as a plugin one only adds the ability to access its properties, slots and signals from designer. It does not change anything else in its internal working.
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

hatulflezet

Professional

  • "hatulflezet" started this thread

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

7

Friday, June 4th 2004, 1:01pm

Quoted

backgroundOrigin is a Q_ENUM() style. You set it usng the enum as property type.
The user can only use values in the fixed values proposed.


Ok, now we are getting somewhere ;-)
This is EXACTLY the thing I am trying to do - as I wrote in my original post.

I have declared a property which is a Q_ENUM() as well - but what I dont understand is, how do I make the enum value names apear in the designer ?
With other types I dont have this problem, since when you introduce a custom widegt to the designer, among other things, you need to specify its properties.
For that, the designer is offering a fixed list of types, which ofcourse do not have my enum (the only thing I can use instead is "int" type property which will expect an numerical input from the user).
So how do I bring my enum property in to the property list in designer for my custom widget, so that the enum values will be selectable like backgroundOrigin's?

In other words how do I get the GREY, RGB565, RGB32 ect, to be selectable values for the property videoMode in designer?

I hope I made my self clear enough....

I am attching the class decleration of my custom widget, to make things clear.

class QGrabber :public QWidget, public IhGrabber
{
Q_OBJECT
Q_ENUMS( VideoMode )
Q_PROPERTY( QString device READ getDevice WRITE setDevice )
Q_PROPERTY( int channel READ getChannel WRITE setChannel )
Q_PROPERTY( VideoMode videoMode READ getVideoMode WRITE setVideoMode )

public:
enum VideoMode { GREY=VIDEO_PALETTE_GREY , RGB565=VIDEO_PALETTE_RGB565, RGB24=VIDEO_PALETTE_RGB24, RGB32=VIDEO_PALETTE_RGB32 };
VideoMode videoMode;
QString device;
int channel;
int m_mode;
//.......
}


Thanks for your help!
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"

This post has been edited 1 times, last edit by "hatulflezet" (Jun 4th 2004, 1:35pm)


djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

8

Friday, June 4th 2004, 3:58pm

Quoted

Ok, now we are getting somewhere ;-)
This is EXACTLY the thing I am trying to do - as I wrote in my original post.

That is also what I understood and why I told you about Q_ENUMS().

Quoted

I have declared a property which is a Q_ENUM() as well - but what I dont understand is, how do I make the enum value names apear in the designer ?

If you create a real plugin widget, not a custom one, this goes smoothly and is transparent. The only thing you have to do is reading Creating Custom Widgets with Plugins in Assistant :D.
You only have to think telling Qt, Designer (and all other apps) that a brand new widget group is available. This is easy with qtconfig in the Library Paths section. Then restart Designer, and voilĂ  8)

Quoted

With other types I dont have this problem, since when you introduce a custom widegt to the designer, among other things, you need to specify its properties.
For that, the designer is offering a fixed list of types, which ofcourse do not have my enum (the only thing I can use instead is "int" type property which will expect an numerical input from the user).
So how do I bring my enum property in to the property list in designer for my custom widget, so that the enum values will be selectable like backgroundOrigin's?

This cannot be done with custom widgets, as Qt and Designer do not know about your own enums, sets, maps and much. Creating real plugin libraries is far more powerful, once you get acustomed to.

Quoted

I am attching the class decleration of my custom widget, to make things clear.

Simply change the declaration as follows:

Source code

1
2
3
#include <qwidgetplugin.h>

class QT_WIDGET_PLUGIN_EXPORT QGrabber :public QWidget, public IhGrabber

Use the base plugin.cpp and plugin.h for Qt documentation. Make a project as LIB, compile, link install. That's all. And your hairy problem will be solved. More, plugin widgets may be reused everywhere, even in KDE or QtEmbedded...
djanubis has attached the following file:
  • qtconfig.png (72.87 kB - 123 times downloaded - latest: Jul 20th 2012, 4:21pm)
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

hatulflezet

Professional

  • "hatulflezet" started this thread

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

9

Friday, June 4th 2004, 5:23pm

I could not wish for a better answer! :D
I suspected it will be only possible as a plugin... :rolleyes:
So basicaly, the answer is - in order to have "pre set" property selectable values in designer the widget needs to be created as a plugin - right?
I will certainly give it try!
Thanks!
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"