PDA

View Full Version : How can I see custom components in QtDesigner?



mauri23
1st December 2016, 10:16
I am developing a Qt Quick 2 Application using QML to define my components.

I would like to create a folder in the project where to put common components (such as customized buttons or labels), and specifically I would like to see this components in the Qt Designer view, in order to be able to drag-drop those elements while designing new views.

I see that the Qt Designer view only shows to you the components located at the same path of the qml that you are currently developing, but I haven't found a way to display components located in other paths.

The project tree should be something like this:


RootFolder
CommonComponents
Views



where the qmls developed in the Views folder will use components defined in the CommonComponents folder.

Does anyone know how to configure the project or the QtDesigner in order to achieve this goal? Thanks

anda_skoa
3rd December 2016, 12:48
Does the file you are designing have the import for your component directory?

Cheers,
_

mauri23
3rd December 2016, 13:01
Yes it has the import statement.
The point is that the import allows me to use the component by manually editing the current ui.qml, but the side effect is that the preview in the designer will be no longer available.
Morover the component is still not shown in the designer library section.

anda_skoa
3rd December 2016, 21:59
Hmm, since you said components on the same path are shown I hoped that was because these were implicitly imported.

Does your component directory have a qmldir file?

Does it help if you set QML2_IMPORT_PATH to include your component directory before launching QtCreator?

Otherwise we'll probably have to look at the code to see how it determines viable directories.

Cheers,
_

mauri23
14th December 2016, 21:01
Yes there is a qmldir file in the directory, listing the files as described herehttp://doc.qt.io/qt-5/qtqml-syntax-directoryimports.html#directory-listing-qmldir-files
But nothing seems to happen while having or not having this file