[Qt-qml] How to extend QML TextEdit (QDeclarativeTextEdit)?

Gregory Schlomoff gregory.schlomoff at gmail.com
Fri Jul 15 21:55:25 CEST 2011


Depending on what you're trying to achieve you could either:

Option 1 - Create a QDeclarativeItem that takes a TextEdit as a
property, and interact with it from your cpp code with getProperty /
setProperty:

MyTextEdit {
  textEdit: TextEdit {}
}

In your cpp code:

class MyTextEdit : public QDeclarativeItem
{
  Q_PROPERTY(QDeclarativeItem* textEdit ... )
}

Then you can use get / set property to interact with the text edit.
Basically, you'd be using composition instead of inheritance, which
generally is a a Good Thing, but sometime doesn't allow you to do what
you want.

Option 2. Include the private header nonetheless. If you're linking to
Qt statically, or if you are distributing the library alongside with
your executable (this is the norm on Windows and Mac), then you
probably don't mind that much linking to a private header. You'll just
have to accept the fact that your code may not compile with newer
versions of Qt, and that you'll have to fix that by hand.

Option 3. Get rid of QDeclarativeTextEdit, and try to embed a
QTextEdit through a QGraphicsProxyWidget. It usually doesn't work that
well. Not recommended.



On Fri, Jul 15, 2011 at 12:26 PM, Cornelius Hald <hald at icandy.de> wrote:
> Hi,
>
> I'd like to extend the TextEdit item in QML. The C++ code is in
> qdeclarativetextedit.cpp but the problem is that I can't find any public
> headers - only private ones.
>
> Originally I thought I'll create a sub-class, but it would also be ok to
> do it differently. Does anyone have an idea?
>
> Thanks!
> Conny
>
>
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>



-- 
Gregory Schlomoff
http://www.gregschlom.com


More information about the Qt-qml mailing list