Re: Still need help: Best way to have application "skins"?
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! :D
Re: Still need help: Best way to have application "skins"?
Quote:
Originally Posted by
codeslicer
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! :D
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?
Code:
class MyFancyWidget
{
...
private:
Ui::FancyWidget fancyUi;
Ui::PlainWidget plainUi;
...
};
void MyFancyWidget::setFancyMode()
{
...
myTextObject = fancyUi.myTextObject;
}
void MyFancyWidget::setPlainMode()
{
...
myTextObject = plainUi.myTextObject;
}
Re: Still need help: Best way to have application "skins"?
Great!! Thanks! It would take me several years to think of that one! :eek:
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! :p
Re: Still need help: Best way to have application "skins"?
Quote:
Originally Posted by
codeslicer
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...
Do you mean something like:
Code:
QPushButton* button
= findChild<QPushButton
*>
("myButtonWithCertainObjectName");
if (button) // just to assure it was found
button->doSomething();
// or
QList<QPushButton*> allButtons = findChildren<QPushButton*>();
button->doSomething();
Quote:
Also, where would I put the connect()'s? In each of the plainUi and fancyUi functions, or in the constructor?
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.
Re: Still need help: Best way to have application "skins"?
Quote:
Originally Posted by
codeslicer
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?
You can also have a common base class with objects common to the two "modes" and two subclasses - one "plain" and one "fancy".
Re: Still need help: Best way to have application "skins"?
@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:
Code:
void MyFancyWidget::setFancyMode()
{
myTextObject = fancyUi.myTextObject;
myButtonObjectt = fancyUi.myButtonObject;
}
void MyFancyWidget::setPlainMode()
{
...
myTextObject = plainUi.myTextObject;
myButtonObject = plainUi.myButtonObject;
}
I could use:
Code:
for(int i=0; i<fancyUi.children().size(); i++) {
childrenList[i]
}
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.
Or, could I use this?
Code:
using namespace fancyUi
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!
Re: Still need help: Best way to have application "skins"?
Quote:
Originally Posted by
codeslicer
@wysota - maybe I don't get it, but the buttons, textboxes, labels, etc are children of each of the respective forms.
So where is a problem with that?
Re: Still need help: Best way to have application "skins"?
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. ^
Re: Still need help: Best way to have application "skins"?
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.
Code:
//...
};
class Plain : public Base, private Ui::BaseForm {
//...
};
class Fancy : public Base, private Ui::FancyForm {
//...
};
//...
Base *window = new Fancy(...);
// or
Base *window = new Plain(...);
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.
Re: Still need help: Best way to have application "skins"?
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 would :o So again, thanks for all this help, this forum is the best I've been on :D
Re: Still need help: Best way to have application "skins"?
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:
or direct declarations:
Code:
myLineEdit = plainUi.myLineEdit;
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 :p
Re: Still need help: Best way to have application "skins"?
Quote:
Originally Posted by
codeslicer
Ok, I'm sorry but I don't understand what you mean by having a base and 2 subclasses...
Hmm... you know what a "class" in object oriented language is, right?
Quote:
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.
Yes, I have read what you had written :)
Quote:
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.
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.
Re: Still need help: Best way to have application "skins"?
I kinda want to keep it a secret for now... :p
But my two ui files are different, yet same. Here's what I mean.
In the plain one, all I have is a tabwidget and several group boxes w/different buttons and such.
Now in the fancy one, I still have that same tab widget, But it is surrounded by a layout of QLabels, which, combined with setMask(), form the dialog's unique display. So in other words, it still contains the same objects, but more, with more styles and images.
Re: Still need help: Best way to have application "skins"?
Quote:
Originally Posted by
codeslicer
I kinda want to keep it a secret for now... :p
I'm going to keep the solution a secret as well then. Most probably (with about 99.9% probability) you don't need two UI files, one is enough to obtain both modes.
Re: Still need help: Best way to have application "skins"?
Well, either I'm wrong, or I have a 0.01 chance of getting this right. Attached, you will find screen shots of my program(Yes it might look a bit "weird" but here it is...)
2 Attachment(s)
Re: Still need help: Best way to have application "skins"?
Yes, you can do that using a single UI. Attached you'll find a UI with two different stylesheets set. Combined with setMask you'll achieve the effect you want.
Re: Still need help: Best way to have application "skins"?
Well, those "borders" are images. Also, they need to dynamically expand, so there are severl of them, all different. Using stylesheets, would I just set the QLabel image to nothing?
Re: Still need help: Best way to have application "skins"?
Quote:
Originally Posted by
codeslicer
Well, those "borders" are images. Also, they need to dynamically expand, so there are severl of them, all different.
It's all achievable using style sheets.
Re: Still need help: Best way to have application "skins"?
Thanks, I'll try that.
But what should I do, create "placeholders" for those images?
Re: Still need help: Best way to have application "skins"?
No. Just style the form or put a frame in the form and style it like I did in the images I posted "border" and "border-image" statements are your friends.