Hi,

when testing the Qt 6.2 rc I noticed that registering custom string converters with
QQmlMetaType::registerCustomStringConverter() has been dropped.

( Yes, QQmlMetaType is from the private API where no compatibility policies are made )

Actually I'm not interested in having a custom string converters - I was using it as a workaround to be able to create a margin that is made from 4 values ( left, top, right, bottom ) from a single
value in QML.

Instead of writing:

    Box
    {
         margins
         {
              left: 10
              top : 10
              right : 10
              bottom: 10
         }
    }

I would like to have the option to write it that way:

    Box
    {
        margins : 10
    }
}

Here is my solution - one I do not like much - but it worked until Qt 6.2:

For some reason neither the Qt metatype system nor the QML engine has specific support for QMarginsF - like what is implemented for classes other standard Qt types like QPointF/QRectF/QSizeF ...

So I derived from QMarginsF and exposed it to QML using Q_GADGET.
See https://github.com/uwerat/qskinny/blob/master/src/common/QskMargins.h

To make the single value assignment possible I added the following:

    QQmlMetaType::registerCustomStringConverter( qMetaTypeId< QskMargins >(),         []( const QString& s ) { return QVariant::fromValue( QskMargins( s.toDouble() ) ); } );

Is the a way to accomplish something similar with Qt 6.2 ?

Thanks,
Uwe




_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to