0

We are multiple people working on one Qt app. I for one am implementing a library, which will be instanciated in multiple other parts of the app. This library has a display class+form along with it.

Until now I had simply created one single instance of the library, running on a dummy, and passed debug data to one instance of the display+form, and worked like that.

But now that core debugging is finished, goal is to have everything instantiable - not just the core library code, but also the form itself, and embed that form into other displays. Each caller/user would be reponsible for passing output data of the core library instance they are using to an instance of the form. Each instance of the form would separately display the information generated by a specific library instance, possibly with different display options - they are all independent.

Similarly, it is possible to enter values in my display. Goal is to be able to enter different values in different displays instantiated accross the app, and sending those to specific instances (caller's responsiblity).

Question is of course : how to do that ? Internet talks about promoting, but I still don't see anywhere in Qt Designer where to include so-called promoted objects in other objects.

TL;DR : : I want some existing form to appear in the menu on the left in Qt Designer to be able to instantiate it multiple times in other forms. How to do this ?

Thanks in advance for the help !

Charles

C. THIN
  • 147
  • 3
  • 11
  • Perhaps this is helpful: "promotion" means that Designer will show some widget class X in its UI while you use it, but the code it generates will actually use the promote-to widget class Y. – hyde May 23 '16 at 17:09

2 Answers2

2

You can promote any QWidget to your control from within Qt Designer. Add a QWidget, right-click and promote.

Ideally, you should create a designer plugin for your control, make the relevant properties designable, and build the plugin as well as the library. That way you'll be able to drag your control from the palette, and it will behave like the real thing.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • So you mean make a separate project with a .pro file of its own ? Sounds overkill to me ... – C. THIN May 24 '16 at 07:37
  • @C.THIN Yes, you need to create a separate project to fully integrate your widget into Qt Designer - that's really a minor thing to do. Shouldn't take more than a couple minutes and a couple lines. There are examples of designer plugins, it's almost a copy-paste job. OTOH, if you're talking about what it takes to simply use your widget without designing its class-specific properties, then you just need to right-click and promote. Any complex piece of software will end up with multiple sub-projects etc., it's not overkill. – Kuba hasn't forgotten Monica May 24 '16 at 12:52
1

Qt QWidget multiple instances

You answered yourself. Qt Creator: "File->New->Qt->Qt Designer Form Class" with QWidget as a base class will suit you. Then you can promote a simple QWidget in the UI into this custom widget, to create an instance. Each instance will manage its own UI.

LogicStuff
  • 19,397
  • 6
  • 54
  • 74
  • I could only promote the first inner widget of my form, and not the global one, but that fine. That being done, where do I find my newly-promoted QWidget for inserting into other forms ? – C. THIN May 24 '16 at 07:36
  • Ah, I misunderstood. It is the widget in the *caller* module display that you want to promote to the *existing* library class module display. But like so, I cannot click on promote, the button is grayed out ... – C. THIN May 24 '16 at 08:01
  • 1
    Oops, wrong base class. Now promoted, works ! Thanks a lot ! – C. THIN May 24 '16 at 08:24
  • @C.THIN You're welcome, I didn't think using it in you UI by promoting a widget would be the hard part. I didn't even mention it. Will fix that. – LogicStuff May 24 '16 at 08:33