1

I designed a Qt application by Qt creator. As you well know when you build a new form is possible to drag an drop the default items inside the main window. Instead of use classical "push button" I created a custom button by adding .qml file to the project. The problem now is that I don't know how I can use (or integrate) the new button inside the form of my project.

Thanks in advance

dtech
  • 47,916
  • 17
  • 112
  • 190
CecchinoSMI
  • 169
  • 13
  • See http://www.youtube.com/watch?v=k5gMAMSz77Q – Mihai8 Apr 11 '14 at 13:25
  • this youtube guide...doesn't help me...I know how create a qml button or object....the problem is to integrate it in an existing qt application form.... – CecchinoSMI Apr 11 '14 at 13:29
  • Do you mean you're trying to use the QML button you created inside a QtWidget form? I believe this could be tricky, but I don't really know for sure. – GabrielF Apr 11 '14 at 15:04
  • @GabrielF - I did not even assume such an extremity, but you never know. – dtech Apr 11 '14 at 15:05
  • Seems like it's actually very easy: http://qt-project.org/doc/qt-4.8/qml-integration.html – GabrielF Apr 11 '14 at 15:10
  • I meant the context of the question, not integrating qml and qwidget. Also, he doesn't seem to mention widgets at all. – dtech Apr 11 '14 at 15:12
  • @ddriver he doesn't. He mentions "existing qt application form", and qwidget is all I could think of that hasn't yet been covered by your answer. Who knows... hehe – GabrielF Apr 11 '14 at 16:51
  • Which Creator version? Try updating. –  Apr 12 '14 at 11:29
  • @user2341104 the version of Creator is 5.2.1 – CecchinoSMI Apr 16 '14 at 09:06

2 Answers2

1

As long as your component is in the path of your application qml files, all you need to use your component is to place it somewhere. You don't need to include or import anything. Any user component is directly available to the entire project.

As long as the QML component is made from only built in components, it can even be safely loaded from arbitrary location on disk, over network or just from a source string. Check this answer for details on dynamic instantiation.

A friendly advice - type the code, do not use the visual editor - it is pretty weak.

EDIT: I don't know about you, but for me, seems like every custom qml file in the project qml folder is automatically added to the QML types in the designer library. So contrary to what I assumed, you shouldn't really need to do anything to get your custom type available for use in the designer.

Community
  • 1
  • 1
dtech
  • 47,916
  • 17
  • 112
  • 190
  • 1
    maybe my question is not clear...but from your answer I understand nothing. – CecchinoSMI Apr 11 '14 at 13:58
  • As I said, forget the visual editor, create your component `Button.qml` and use it in `main.qml` by simply typing `Button {}`. This will create an instance of the Button.qml component inside main.qml. – dtech Apr 11 '14 at 13:59
  • Yes but...this means that it is impossible to use a custom button created in qml inside a qt application created previously? – CecchinoSMI Apr 11 '14 at 14:29
  • What is your logic for making such claims? Of course it is possible, you seem to have a lot of misconceptions. – dtech Apr 11 '14 at 14:43
  • Sorry...but if it is possible....why you suggested me an other way? If you know how create a button in qml and import it in a qt form...please explaine. I don't know where is the wrong idea.... – CecchinoSMI Apr 11 '14 at 14:56
  • I have already explained that in the answer. I am not suggesting "another way" - I listed every way possible. I still don't understand what is it exactly that *you* don't understand... You don't seem to know what you are doing. You can either use the declarative approach and put the qml file in your project, or you can use the dynamic approach and load QML from arbitrary file or source string. – dtech Apr 11 '14 at 14:59
1

I found this 1 year-old question when facing the same problem. This is what I found out:

If you save your custom button with an initial uppercase letter (CustomButton.qml instead of customButtom.qml), QtDesigner shows your component in the library panel correctly.

Sometimes you need to restart QtDesigner to work.

rcmadruga
  • 817
  • 12
  • 18