Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, May 2007
Qt Designer and own classes


Message 1 in thread

Hi,

former versions of the Designer (e.g. in Qt3) offered the possibility
to declare own classes as custom widgets just by providing their class
name and the name of their header file in the designer.

The current designer seems to lack this (and some more) functionality.

Has anyone found a way to insert own classes into the designer without
the horrible plugin approach? Please don't understand me wrong - I still
have some plugins, but for most cases this approach doesn't work - especially
with a static Qt lib and app.

Any hints are appreciated.

Best Regards,
Christian

PS: I just want to use a derived QLabel class inside a UI file -
    no preview or so is needed.


--
 [ signature omitted ] 

Message 2 in thread

> PS: I just want to use a derived QLabel class inside a UI file -
>     no preview or so is needed.

Just use provided QLabel-Widged, right click on the item in Designer and 
choose "Promote to custom widget". There you enter your custom Class Name 
and header file name and there you are :-)

Regards,

Malte

--
 [ signature omitted ] 

Message 3 in thread

search  "promote widget" in qtdesigner4 doc.
this is a powerfull "custom widget" mechanism.
drag&drop custom widget base component
of custom component you want to install in the form you design with 
qtdesigner4.
(example, you create your own label,drag&drop a qlabel in the form in 
right place)
right click this widget and select "promote widget" item.
enter the header file and class name like in qtdesigner for custom widget.
the difference is that you'll have access to allproperties of the widget 
promoted. this was not possible with custom widgets in qtdesigner3.


Christian Dähn a écrit :

>Hi,
>
>former versions of the Designer (e.g. in Qt3) offered the possibility
>to declare own classes as custom widgets just by providing their class
>name and the name of their header file in the designer.
>
>The current designer seems to lack this (and some more) functionality.
>
>Has anyone found a way to insert own classes into the designer without
>the horrible plugin approach? Please don't understand me wrong - I still
>have some plugins, but for most cases this approach doesn't work - especially
>with a static Qt lib and app.
>
>Any hints are appreciated.
>
>Best Regards,
>Christian
>
>PS: I just want to use a derived QLabel class inside a UI file -
>    no preview or so is needed.
>
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>  
>

--
 [ signature omitted ] 

Message 4 in thread

Use a normal QLabel in designer, right-click on it and pick "Promote to 
Custom Widget".


Marc

qt-interest-request@xxxxxxxxxxxxx wrote on 14-05-2007 15:12:58:

> Hi,
> 
> former versions of the Designer (e.g. in Qt3) offered the possibility
> to declare own classes as custom widgets just by providing their class
> name and the name of their header file in the designer.
> 
> The current designer seems to lack this (and some more) functionality.
> 
> Has anyone found a way to insert own classes into the designer without
> the horrible plugin approach? Please don't understand me wrong - I still
> have some plugins, but for most cases this approach doesn't work - 
especially
> with a static Qt lib and app.
> 
> Any hints are appreciated.
> 
> Best Regards,
> Christian
> 
> PS: I just want to use a derived QLabel class inside a UI file -
>     no preview or so is needed.
> 
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx 
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

Message 5 in thread

Hi,

thanks a lot for the fast replies!

But I've a little problem: My own QLabel class was declared
inside of a namespace - and the UIC cannot handle this - even
if I add the namespace to the class name.

Has anyone experienced comparable problems?

Best Regards,
Christian


--
 [ signature omitted ] 

Message 6 in thread

Sorry Chrstian for the private reply....

when you promote the widget, you can set the header file like this
MyFolder/MyHeader.h
for the class name, you can do this
MyNameSpace::MyClass

here the contents of a .ui where I promote a class that is in a namespace
<customwidgets>
 <customwidget>
  <class>Inscape::InQLuaTextEdit</class>
  <extends>QTextEdit</extends>
  <header>Inscape/InQLuaTextEdit.h</header>
 </customwidget>
</customwidgets>


Veronique.




Christian Dähn a écrit :

>Hi,
>
>thanks a lot for the fast replies!
>
>But I've a little problem: My own QLabel class was declared
>inside of a namespace - and the UIC cannot handle this - even
>if I add the namespace to the class name.
>
>Has anyone experienced comparable problems?
>
>Best Regards,
>Christian
>
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>  
>

--
 [ signature omitted ] 

Message 7 in thread

Hi,

> when you promote the widget, you can set the header file like this
> MyFolder/MyHeader.h  for the class name, you can do this
> MyNameSpace::MyClass

Mhm - I tried it exactly this way - and set the path to the header file -
but the QFormBuilder still cannot create the widget.

For testing purposes I removed the namespace completely from the widget
and the class calling the QFormBuilder (QUILoader) - but this didn't
change anything :-(

Best Regards,
Christian



--
 [ signature omitted ] 

Message 8 in thread

This work for me but I don't load dynamically the ui files so... maybe 
it's not accepted by the qformbuilder?

Ask to trolltech support if this is possible?



Christian Dähn a écrit :

>Hi,
>
>  
>
>>when you promote the widget, you can set the header file like this
>>MyFolder/MyHeader.h  for the class name, you can do this
>>MyNameSpace::MyClass
>>    
>>
>
>Mhm - I tried it exactly this way - and set the path to the header file -
>but the QFormBuilder still cannot create the widget.
>
>For testing purposes I removed the namespace completely from the widget
>and the class calling the QFormBuilder (QUILoader) - but this didn't
>change anything :-(
>
>Best Regards,
>Christian
>
>
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>  
>


Message 9 in thread

you can't dynamically load a custom widget defined in this way.

if you really need to dynamically load it, you'll have to make it a designer plugin.

Cheers,
Peter

> -----Ursprüngliche Nachricht-----
> Von: Christian Dähn [mailto:daehn@xxxxxxxxxx]
> Gesendet: Montag, 14. Mai 2007 18:29
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: Re: Qt Designer and own classes
> 
> Hi,
> 
> > when you promote the widget, you can set the header file like this
> > MyFolder/MyHeader.h  for the class name, you can do this
> > MyNameSpace::MyClass
> 
> Mhm - I tried it exactly this way - and set the path to the header file -
> but the QFormBuilder still cannot create the widget.
> 
> For testing purposes I removed the namespace completely from the widget
> and the class calling the QFormBuilder (QUILoader) - but this didn't
> change anything :-(
> 
> Best Regards,
> Christian

--
 [ signature omitted ] 

Message 10 in thread

Hi,

> you can't dynamically load a custom widget defined in this way.
> 
> if you really need to dynamically load it, you'll have to make it a designer plugin.

Thats very dissatisfying :-(  In former designer versions it was possible
to do it like this way - and even the current docu says that.

So don't misunderstand me: I just want a placeholder for a derived QLabel,
so that the QUILoader will construct the real class on runtime.
Referring to the designer docu this should be possible without any
special plugin, or did I misunterstood the docs?

Best Regards,
Christian


--
 [ signature omitted ] 

Message 11 in thread

You can use the designer to place your own custom widgets, but then you'll also have to use uic and compile/link the result.

If you wanted to load your classes at runtime (i.e. call their constructor) you'd need bindings for them. Standard C++ doesn't provide a mechanism for this. So, you'll have to wrap them as plugins if you really need to dynamically load them. Or you could possibly derive your own version of QUiLoader that knows how to create your custom widgets.

Cheers,
Peter

> -----Original Message-----
> From: Christian Dähn [mailto:daehn@xxxxxxxxxx]
> Sent: Tuesday, May 15, 2007 11:03 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: AW: Qt Designer and own classes
> 
> Hi,
> 
> > you can't dynamically load a custom widget defined in this way.
> >
> > if you really need to dynamically load it, you'll have to make it a
> designer plugin.
> 
> Thats very dissatisfying :-(  In former designer versions it was possible
> to do it like this way - and even the current docu says that.
> 
> So don't misunderstand me: I just want a placeholder for a derived QLabel,
> so that the QUILoader will construct the real class on runtime.
> Referring to the designer docu this should be possible without any
> special plugin, or did I misunterstood the docs?
> 
> Best Regards,
> Christian

--
 [ signature omitted ] 

Message 12 in thread

> You can use the designer to place your own custom widgets, but then you'll also have to use uic and compile/link the result.
> 
> If you wanted to load your classes at runtime (i.e. call their constructor) you'd need bindings for them. Standard C++ doesn't provide a mechanism for this. So, you'll have to wrap them as plugins if you really need to dynamically load them. Or you could possibly derive your own version of QUiLoader that knows how to create your custom widgets.

Thanks! Now I got it! So I just have to compile the ui file with uic and then it should work.

Greetz,
Christian


--
 [ signature omitted ] 

Message 13 in thread

Christian Dähn wrote:
> Hi,
>
>   
>> you can't dynamically load a custom widget defined in this way.
>>
>> if you really need to dynamically load it, you'll have to make it a designer plugin.
>>     
>
> Thats very dissatisfying :-(  In former designer versions it was possible
> to do it like this way - and even the current docu says that.
>
> So don't misunderstand me: I just want a placeholder for a derived QLabel,
> so that the QUILoader will construct the real class on runtime.
> Referring to the designer docu this should be possible without any
> special plugin, or did I misunterstood the docs?
>
> Best Regards,
> Christian
>   
Hi Christian,
In the script/tetrix example in Qt 4.3, a custom UiLoader is used to
load such a placeholder widget. Here's the relevant code:

class TetrixUiLoader : public QUiLoader
{
public:
    TetrixUiLoader(QObject *parent = 0)
        : QUiLoader(parent)
        { }
    virtual QWidget *createWidget(const QString &className, QWidget
*parent = 0,
                                  const QString &name = QString())
    {
        if (className == QLatin1String("TetrixBoard")) {
            QWidget *board = new TetrixBoard(parent);
            board->setObjectName(name);
            return board;
        }
        return QUiLoader::createWidget(className, parent, name);
    }
};

When you load the form, you use the custom UiLoader:

    TetrixUiLoader loader;
    QFile uiFile(":/tetrixwindow.ui");
    uiFile.open(QIODevice::ReadOnly);
    QWidget *ui = loader.load(&uiFile);
    uiFile.close();

Regards,
Kent

>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>   

--
 [ signature omitted ] 

Message 14 in thread

> In the script/tetrix example in Qt 4.3, a custom UiLoader is used to
> load such a placeholder widget. Here's the relevant code:

Jippiie! That's what I searched for! Thanks a lot - this should be
a fast solution for my problem!

I'll write my own QUILoader like in the example and then it should work.

Greetz,
Christian


--
 [ signature omitted ]