PDA

View Full Version : Adding New Components to QML Designer



SamFredericks
15th August 2011, 13:36
Hello,

I want to add new Components to my QML Designer in my Qt Creator.
I have found 3 ways to do it:

Project specific:
1.) Create one Component "MyButton.qml" in a subfolder called "custom" inside of your QML-Project.
2.) Create qmldir-file in subfolder "custom" to populate your component.

MyButton 1.0 MyButton.qml
3.) Import your component in your main.qml inside of your QML-Project.

import "custom"

Install QML-Component:
1.) Copy your "custom" folder into QT_PATH/imports/Qt/labs
2.) Import your component in your main.qml

import Qt.labs.custom 1.0
3.) Write an QML-Designer Plugin with a *.metainfo-File, where you populate your Component.

Install QML-Component in CPP:
1.) Write a simple Plugin, where MyButton inherits QDeclarativeItem.
2.) Copy your Plugin with your qmldir-File into QT_PATH/imports/Qt/labs
qmldir-file:
plugin mybuttonplugin
3.) Import your plugin in your main.qml

import Qt.labs.custom 1.0
4.) Write an QML-Designer Plugin with a *.metainfo-File, where you populate your Component.

First Problem:
If I import in an installed-component ("Project specific", "Install QML-Component") a self constructed plugin, for example inside of "MyButton.qml"

import Qt.labs.plugins.mybuttondata 1.0
there will be no preview of "MyButton" inside of the QML Designer.

Second Problem:
If I create my grafical Item "MyButton" by a plugin ("Install QML-Component in CPP"), there will be no preview of "MyButton" inside of the QML-Designer.

Where is my mistake? What else do I have to do?
Thanks for any advice,

Greatz

SamFredericks
2nd September 2011, 11:48
Problem:

If I create my grafical Item "MyButton" by a plugin ("Install QML-Component in CPP"), there will be no preview of "MyButton" inside of the QML-Designer.

Wow.Today I found the solution. I think. By searching for something different......that's life. :confused:

Solution:

Ideally, QML modules have a plugins.qmltypes file in the same directory as the qmldir file. The qmltypes file contains a description of the components exported by the module's plugins and is loaded by Qt Creator when the module is imported.

Using QML Modules defined with C++ as Plugin (http://doc.qt.nokia.com/qtcreator-snapshot/creator-qml-modules-with-plugins.html)

cmessineo
28th June 2012, 15:24
How did you get this to work?

Did you create your plugins.qmltypes file by hand?

I copied my qml files to a "custom" folder into QT_PATH/imports/Qt/labs, but the qml components don't show up in the designer.

Thanks

Le_B
29th June 2012, 12:23
the question you have to answer first withthis tutorial is how do you want to include your custom control in your application ?
dll ? ressource ? plain qml files ?

cmessineo
29th June 2012, 17:15
the question you have to answer first withthis tutorial is how do you want to include your custom control in your application ?
dll ? ressource ? plain qml files ?

I'm just talking about plain old QML files here. I want to copy my files into the QT_PATH/imports/ along with a qmldir file and then when I create a new QML file in the IDE I want to be able to import my files like:

import components 1.0

When I click design mode I'd like the controls to show up in the library/items pane so I can drag the control onto the canvas.

It seems to me that this can not be don. I will have to either tweak the QTCreator code for this to happen, or I will have to some how convert my QML controls to c++ controls.

Le_B
2nd July 2012, 14:36
are you in a qmlproject or qmlApplication ?

Added after 13 minutes:

no need for qmldir if it s plain qml just put
import "/Qt/4.8.1/imports/Qt/custom" in your qml file
save
go to designer