Ok, that's good!
But how do I use 2 seperate ui files in the same class? QUILoader? Sounds slow and looks like it doesn't support multiple inheritance...
Ok, that's good!
But how do I use 2 seperate ui files in the same class? QUILoader? Sounds slow and looks like it doesn't support multiple inheritance...
C++ & AMD forever
What do you intend to do? It makes no sense to load two different .ui's on a single widget, does it? You can use direct approach if you have two different widgets for which you want to load different forms. But by using direct approach you also lose a lot of flexibility. Then why not just wrap those two widgets as separate classes which both use single or multiple inheritance approach...
J-P Nurmi
Thanks for trying to help me. A lot. Maybe I explained myself wrong.
I have this form with style sheets and custom buttons, setMask() enabled on some parts, etc. Then, I have a second form which doesn't use any of that, and uses the Operating System's Style. Now, at first, the "fancy" form is used for the program, but what if the user doesn't like it? Or what if somehow it doesn't work on his/her system? I want the user to be able to chose between using the "fancy" form and the "plain" one.
If I want to have two different forms, with the "fancy" one containing different functions which would be used for setting effects, and the core functions, while the "plain" one will just have the core functions(functions which perform what the program is going to do, ie download and read a file), how would I approach that. Can I have two seperate classes, one which would use the form with the effects, then a seperate one which wouldn't use any effects at all?
Is this possible?![]()
Wouldn't it be only a matter of removing style sheets, custom styles and/or masks (which ever you end up using)?
J-P Nurmi
Well, it's not as simple as myApp->removeStyle() or something like that.
The "fancy" design is completely different, the only things that are the same are the object names...
You mean like the form layout is completely different? I suppose you could use single inheritance approach and have two different ui members:
Qt Code:
#include "ui_plainwidget.h" #include "ui_fancywidget.h" { ... private: Ui::FancyWidget fancyUi; Ui::PlainWidget plainUi; }; void MyFancyWidget::setFancyMode() { saveFormState(); // you might want to store contents if you let user to change mode on the fly qDeleteAll(children()); // or something like this to clear everything, it is important to delete layout() fancyUi.setupUi(this); restoreFormState(); // restore contents } void MyFancyWidget::setPlainMode() { ... plainUi.setupUi(this); ... }To copy to clipboard, switch view to plain text mode
J-P Nurmi
codeslicer (23rd February 2008)
Thanks! Only one question. Later in my code, the "core" of it, how would I refer to the objects on my forms, if they have the same names? Do I have to use plainUi.myTextBoxObject, or can I just ise myTextObject like in multi-inheritance? Thanks again!![]()
That's a good point I didn't think of.Unfortunately those two ui members have nothing in common... How about introducing additional pointers to required objects (hopefully you don't have tons of them) so that you don't have to continuously check the mode and clutter your code with conditional blocks?
Qt Code:
class MyFancyWidget { ... private: Ui::FancyWidget fancyUi; Ui::PlainWidget plainUi; QTextEdit* myTextObject; ... }; void MyFancyWidget::setFancyMode() { ... myTextObject = fancyUi.myTextObject; } void MyFancyWidget::setPlainMode() { ... myTextObject = plainUi.myTextObject; }To copy to clipboard, switch view to plain text mode
J-P Nurmi
codeslicer (23rd February 2008)
Great!! Thanks! It would take me several years to think of that one!
Any chance I could create some for(int i=0; i<childWidgets().length(); i++) loop? Note that childWidgets() may not be an actual property, but for the sake of this question...
So could I somehow apend that name? If it's not possible, it's ok.
I don't need to do much, just a couple of buttons and a text box.
Also, where would I put the connect()'s? In each of the plainUi and fancyUi functions, or in the constructor?
Thanks a lot!![]()
Do you mean something like:
Qt Code:
if (button) // just to assure it was found button->doSomething(); // or QList<QPushButton*> allButtons = findChildren<QPushButton*>(); button->doSomething();To copy to clipboard, switch view to plain text mode
The whole GUI, including all widgets, gets re-created when you call respective setupUi(). So you must re-establish all signal-slot connections every time the "mode" is changed.Also, where would I put the connect()'s? In each of the plainUi and fancyUi functions, or in the constructor?
J-P Nurmi
codeslicer (24th February 2008)
You may use QStyle and make usage of polish() / unpolish() methods to set/unset masks etc.
It would be more flexible when you'll be adding more styles in future (u have all style stuff in single class & you don't have to remember about changes in lots of places in entire application code).
I'm using single style for skins effect that gets images path in constructor and styleplugin searches skins directory and creates an instance of the same style for different images set.
It causes that adding new skins doesn't require coding, just some painting job.
See GrEEn (Graphics Effects Environment)
http://sourceforge.net/project/platf...roup_id=232746
a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).
@wysota - maybe I don't get it, but the buttons, textboxes, labels, etc are children of each of the respective forms.
@jpn - by loop I meant instead of having to use:
Qt Code:
void MyFancyWidget::setFancyMode() { myTextObject = fancyUi.myTextObject; myButtonObjectt = fancyUi.myButtonObject; } void MyFancyWidget::setPlainMode() { ... myTextObject = plainUi.myTextObject; myButtonObject = plainUi.myButtonObject; }To copy to clipboard, switch view to plain text mode
I could use:
I don't really know how to make this, but what I'm trying to do is to dynamically convert all of fancyUi's children into names which wouldn't require prefixing fancyUi.Qt Code:
for(int i=0; i<fancyUi.children().size(); i++) { childrenList[i] }To copy to clipboard, switch view to plain text mode
Or, could I use this?
But this has to be globally declared right? I can't put it in each of the mode-changing functions can I? What I'm trying to do is somehow "fake" the multi-inheritance approach from single inheritance to make life easier. I can make pointers to each single object, but as my program grows this looks like it would involve lots of unneeded code.
Thanks!
Those widgets(buttons, text boxes) are contained in different layouts which have skins, therefore I can't remove those layouts without disrupting the children.
Please read my post above. ^
I don't really see the problem...
Correct me if I'm wrong but essentially you have two versions of the same widget - one with reduced and the other with extra functionality (regardless of how the functionality is presented). So you can have a class that holds the common part of the two versions and two subclasses extending it with functionality unique to each representation. Then it's just a matter of instantiating objects of a proper (depending on the "mode") and cloning the state of the common part from one instance to the other.
Qt Code:
//... }; class Plain : public Base, private Ui::BaseForm { //... }; class Fancy : public Base, private Ui::FancyForm { //... }; //... Base *window = new Fancy(...); // or Base *window = new Plain(...);To copy to clipboard, switch view to plain text mode
BTW. What you are doing is not "skinning" - you have different functionality (at least I assume that based on what you have written in this thread) thus it is something more than just changing the way content is presented.
codeslicer (24th February 2008)
Ok, I'm sorry but I don't understand what you mean by having a base and 2 subclasses...
I have 2 seperate ui files with different styles. The "plain" one contains just the essentials, nothing more than a simple form with no style whats so ever(Other than the style Qt gives to it at run time, based on the OS). Then, I have a "fancy" one which includes the core functions and buttons, etc, but also contains some different actions in the constructor(like setMask()). It also has a different style, like different images, integrated style sheets in Qt Designer, and more.
In my program I want to let the user chose which style he wants. After he chooses, the program restarts, and reads from QSettings what he wants. If it's the fancy style, the program should read the "fancy" ui file and perform extra operations on the main window, in addition to the core commands.
However, if it's plain, then the program should read the "plain" ui file, and only do the core commands.
I received some suggestions from jpn, having setFancyMode() and setPlainMode(), but my question is, how can I transform the application from single-inheritance to multi-inheritance. Ie, I don't want to have to call plainUi.myTextBox, instead calling just myTextBox.
If I create pointers to each object during the setPlainStyle() or setFancyStyle() functions, do I have to somehow globally declare them in the header file, or will they be globally defined already for use in other functions of the same class?
Thanks a lot so far, I think I'm not getting it because I'm kinda new and need more explanation than a normal coder wouldSo again, thanks for all this help, this forum is the best I've been on
![]()
I don't think I need to dynamically redefine all of the objects in the forum, only the essential buttons. One more thing, should I use pointers, ie:
Qt Code:
To copy to clipboard, switch view to plain text mode
or direct declarations:
Qt Code:
myLineEdit = plainUi.myLineEdit;To copy to clipboard, switch view to plain text mode
Also, do I need to declare these in the header file?
Thanks
PS: I can't change the topic title. Can a mod please change it to SOLVED? That would be great, thanks![]()
Hmm... you know what a "class" in object oriented language is, right?
Yes, I have read what you had writtenI have 2 seperate ui files with different styles. The "plain" one contains just the essentials, nothing more than a simple form with no style whats so ever(Other than the style Qt gives to it at run time, based on the OS). Then, I have a "fancy" one which includes the core functions and buttons, etc, but also contains some different actions in the constructor(like setMask()). It also has a different style, like different images, integrated style sheets in Qt Designer, and more.
Do both these UI contain the same widgets (just positioned or styled differently)? Could you maybe attach them to your post so that we may have a look at them? If you only wish to change the look of your widget, you don't need two separate UI files - you can apply different stylesheets on the same set of widgets or set a different style on the widget.In my program I want to let the user chose which style he wants. After he chooses, the program restarts, and reads from QSettings what he wants. If it's the fancy style, the program should read the "fancy" ui file and perform extra operations on the main window, in addition to the core commands.
However, if it's plain, then the program should read the "plain" ui file, and only do the core commands.
codeslicer (24th February 2008)
Bookmarks