How to change windows when comboBox value is selected
-
Im really suprised by the lack of good documentation on combo Boxes. Anyways I have my main class file which is vaportoolkit and then i have a seperate ui file that is coilBuilder.ui how do I if they select the first value in menuComboBox redirect to coilBuilder.ui?
-
Do you have an implementation class for coilBuilder.ui? I mean, a C++ class who inherits from QWidget and it has a member of the class that it is generated by Qt using the ui file.
You need to get the signal emitted when the user clicks in the combobox. In the slot linked to that signal, call a method of your main class.
-
So just as one has a class of vapor toolkit i need to make a instance of a new class coilBuilder?
-
Well asked question is 90% of the answer.
I am not sure about others, but I can't claim I understood your question.I can only guess that your problem has nothing to do with comboboxes.
It is related to lack of understanding either of what designer files provide or general C++ in terms of communication pattern between class instances.
In last case you should visit forums for general C++ questions.If first I would suggest re-reading Qt documentation, but I may try to provide some help which I doubt is easier to understand than documentation.
But I will try.Designer does not produce a complete C++ class which handles your top widget.
All it does it creates a class which has widgets / layouts/ or other members you placed in the designer.So normally your need class derived from a widget (QWidget, QDialog ...QMainWindow). Such class needs instantiate the instance of ui generated files somehow. It is usually done by adding the member (pointer or instance) or through multiple inheritance.
The way it was done defines how you can access ui generated widgets (combobox and any other )If you used class wizard both classes will be generated for you.
If you just generated ui file you will have to do it by hands.Regards,
Alex -
Good answer, Alex.
I recommend this page to get a better understanding about how to use a UI file in your project.
http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
-
bresser, there is different approch and way to make some change appear with QCombobox selected... also, for sure, the documentation is minimalist (and sometime more than minimalist).
first, has you can see from your QtDesigner (i think, because you talk about a .ui file, you construct it from QtDesigner), you can choose to add a "slot" (right click on the comboBox and inside the contextual menu, click "add slot"... then an dialog window open and you need to choose the method slot to hang when signal is emit by the combobox action... here, you can again the doc to try to understand what they suggest... but the principe is to be able to imagine by the arguments wich signal could be used for your need).
Then, inside the class who use the ui, this slot has to be automatically writed, and the QtCreator Editor will show you this inside the cpp file of your class who is declared to use the ui.
Then, you can add your code inside and use the argument passed trough from the emited signal (in general, a "int" type arguments from the "currentIndexChanged(int index)" will give you wich ligne (from 0 to end line number -1) you clicked.
You can choose to use the QString value back if you need.from this point, you can choose to do what you want:
1 show() or open() an other QDialog window
2 change the content of a QStackedWidget (this one can embed layouts form with all that you need, but stay inside your window)
3 call a MDI window from your mainWindow (i think maybe that you want)
4 close some other QDialog allready open by an old click/selection from your Comboboxbut... this are some ideas (and maybe not full listed), i don't really know what you really want to do for your application. There is many ideas to be able to use and many Widgets containers who can do similar job.
Some of them are more simple than some other (for me...).
if you really want to open a window, solution 1 or 3 could be the idea... but also, you need to know for the solution one, if the QDialog (your window) has to be unique or not, modal or not modal, if some other windows has to be close at the same time or not, etc...i hope this could help. (and good luck with the doc... :) )