Promoting? What's that? How can I put a QWidget I made into a dock window?
-
I made a subclass of a QDockWidget (composed of RecentProjectsDockWindow.ui, RecentProjectsDockWindow.h and RecentProjectsDockWindow.cpp). It's lovely. I made it appear on my GUI and behave nicely as a dock window should. I created it using the "Add New" right-click option in the Projects window in QT Creator.
I also made a subclass of a QWidget in pretty much the same way(composed of RecentProjectsListWidget.ui, RecentProjectsListWidget.h and RecentProjectsListWidget.cpp); it is a Qwidget, it's just got a name with the word "list" in it because that's principally what it's going to be for. This QWidget has some other things inside it; it has a QListView and a QTableView inside it, which I put there using the Design Mode editor of QT Creator (just dragged them in from the big list of widgets on the left, which I see adds them to RecentProjectsListWidget.ui). It is a happy QWidget.
I want the dock widget known as RecentProjectsDockWindow to contain within it as object of type RecentProjectsListWidget, which as discussed is a QWidget object. Obviously, the big list of objects on the left doesn't contain one of my special RecentProjectsListWidget QWidget objects, so I can't just drag it in.
I look on the web and apparently I should be able to "promote" my Qwidget object... to a QWidget object? It already is a QWidget object (or rather, it's a subclass of a QWidget object). That said, all the web pages I find say I should be able to right-click it and see option "Promote To" but all I see is "Promoted Objects"; I note that "Promoted Objects" contains something very similar that the previous team who worked on this must have done, so it certainly looks like that's what I want to do. They managed to get their ProjectListWidget into a DockWindow, and I'm trying to do something very similar. The previous team lives in another country and for whatever reason they're not contactable. It's now just me.
Could someone explain to me what happens "under the hood" when I promote an object, and how I can promote my RecentProjectsDockWindow class so that I am then able to put one inside my RecentProjectsDockWindow GUI?
Apologies for the long post; I often find explaining what I want to actually do goes a long way towards smoothing over my inexperience and lack of knowledge.
-
First of all you don't promote your widget to anything. You promote one of the basic designer widget types to yours.
The concept is to put a basic base class widget in the designer (a dummy if you will) and then "promote" it to be substituted by your own class.
What is happening under the hood is quite simplistic. You put a widget in a designer (say a simple QWidget), then you mark it to be promoted to your class.Now enter the uic(ui compiler). It takes the .ui file(which is an xml ui definition basically), analyzes it and generates a ui_whatever.h header that gets included in your code and contains the actual c++ code that creates ui.
For the usual widgets (dragged from the panel in the designer) it just adds an #include statement for it, generates a class member and initializes it with a new QWidget(...) statement (or QFrame, QDockWidget or whatever the thing is).
Now for promoted widgets it's almost the same, except it adds an #include statement for the class the widget was promoted to instead of the basic one, so #include "yourwidget.h" and the member is of your promoted type.The whole process is described "here":http://qt-project.org/doc/qt-5.1/qtdesigner/designer-using-custom-widgets.html
In your particular case if the right-click menu says "Promoted widgets" it means that the widget(or a dock or whatever) is already promoted to something (take a look at the object hierarchy on the right to see what to). A widget can't be promoted to more that one thing at a time (well obviously) so if you want to promote it to your new thing you need to demote it first to its basic type ("Demote to (...)" in the right click menu).
So to put a RecentProjectsListWidget in the RecentProjectsDockWindow you add a basic QWidget to your RecentProjectsDockWindow, right click it and promote it to your RecentProjectsListWidget.Sorry for the lengthy response :)
-
Lots of words very much appreciated, thanks; to a newcomer, in this context "promote" carries no actual meaning - until I understand what actually happens, it's just a magic incantation (nothing against QT in this respect - it's the case with everything that internal vocabulary is a black box to outsides).
As you explained, the mistake I was making was that I was right-clicking on the UI designer view of my custom widget, looking to promote it, when of course what I wanted was to place some other widget (a QWidget is what I chose in the end) into where I wanted to actually put my custom widget, and then promote that placeholder widget. Which all seemed to work, many thanks.
-
@Chris, Thanks for nice explanation.
I created a QWizardPage form using QT Form Designer(call it XYZ.ui), promoted it XYZWizradPage. I removed that Wizard form and the XYZWizardPage class.
I added a new QWizardPage(ABC.ui), and a new class to promote it (ABCWizardPage). I want to promote ABC.ui to ABCWizardPage class.Promoted widget class XYZWizardPage is there. I am unable to remove it.
Secondly, "Promote" button is not enabled after adding ABCWizardPage class in promoted widgets[quote author="Chris Kawa" date="1380189145"]First of all you don't promote your widget to anything. You promote one of the basic designer widget types to yours.
The concept is to put a basic base class widget in the designer (a dummy if you will) and then "promote" it to be substituted by your own class.
What is happening under the hood is quite simplistic. You put a widget in a designer (say a simple QWidget), then you mark it to be promoted to your class.Now enter the uic(ui compiler). It takes the .ui file(which is an xml ui definition basically), analyzes it and generates a ui_whatever.h header that gets included in you code and contains the actual c++ code that creates ui.
For the usual widgets (dragged from the panel in the designer) it just adds an #include statement for it, generates a class member and initializes it with a new QWidget(...) statement (or QFrame, QDockWidget or whatever the thing is).
Now for promoted widgets it's almost the same, except it adds an #include statement for the class the widget was promoted to instead of the basic one, so #include "yourwidget.h" and the member is of your promoted type.The whole process is described "here":http://qt-project.org/doc/qt-5.1/qtdesigner/designer-using-custom-widgets.html
In your particular case if the right-click menu says "Promoted widgets" it means that the widget(or a dock or whatever) is already promoted to something (take a look at the object hierarchy on the right to see what to). A widget can't be promoted to more that one thing at a time (well obviously) so if you want to promote it to your new thing you need to demote it first to its basic type ("Demote to (...)" in the right click menu).
So to put a RecentProjectsListWidget in the RecentProjectsDockWindow you add a basic QWidget to your RecentProjectsDockWindow, right click it and promote it to your RecentProjectsListWidget.Sorry for the lengthy response :)[/quote]
-
Sorry, but I can't understand what you're doing and what you want to do.
[quote]I created a QWizardPage form using QT Form Designer(call it XYZ.ui), promoted it XYZWizradPage.[/quote]You promoted a QWizardPage to XYZWizardPage? Am I understanding correctly?[quote]I removed that Wizard form and the XYZWizardPage class.[/quote]Removed them from where?
[quote]I added a new QWizardPage(ABC.ui), and a new class to promote it (ABCWizardPage). I want to promote ABC.ui to ABCWizardPage class.[/quote]Sorry but that doesn't make sense. You want to promote a file to a c++ class?
[quote]Promoted widget class XYZWizardPage is there. I am unable to remove it.[/quote]Where? remove it from what? -
Dear Chris, thanks for your reply. I added explanation to your text in bold face.
[quote author="Chris Kawa" date="1405693691"]Sorry, but I can't understand what you're doing and what you want to do.
[quote]I created a QWizardPage form using QT Form Designer(call it XYZ.ui), promoted it XYZWizradPage.[/quote]You promoted a QWizardPage to XYZWizardPage? Am I understanding correctly?[quote]
Yes, you are rightI removed that QWizardPAge form and the XYZWizardPage class.[/quote]Removed them from where?
I deleted the wizard page and respective class (XYZWizardPage) from the project
[quote]I added a new QWizardPage(ABC.ui), and a new class to promote it (ABCWizardPage). I want to promote ABC.ui to ABCWizardPage class.
[/quote]Sorry but that doesn't make sense. You want to promote a file to a c++ class?
I want to promote QWizardPage in ABC.ui file to class ABCWizardPage[quote]Promoted widget class XYZWizardPage is there. I am unable to remove it.[/quote]Where? remove it from what?
[/quote]
Previously promoted QWizardPage [XYZWizardPage]exits in the list of PromotedWidgets and I can't remove it -
If you can't remove an entry in the promoted widgets window it means something is still promoted to it. Check your hierarchy tree view to see what that is.
You can also find/edit/remove it manually by looking at the file in text form. It's a simple XML format. Promoted widgets list is usually located near the bottom and you can use text search to find what is promoted to "XYZWizardPage".