Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 54

Thread: Still need help: Best way to have application "skins"?

  1. #21
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Arrow 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!

  2. #22
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Still need help: Best way to have application "skins"?

    Quote Originally Posted by codeslicer View Post
    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:
    1. class MyFancyWidget
    2. {
    3. ...
    4. private:
    5. Ui::FancyWidget fancyUi;
    6. Ui::PlainWidget plainUi;
    7.  
    8. QTextEdit* myTextObject;
    9. ...
    10. };
    11.  
    12. void MyFancyWidget::setFancyMode()
    13. {
    14. ...
    15. myTextObject = fancyUi.myTextObject;
    16. }
    17.  
    18. void MyFancyWidget::setPlainMode()
    19. {
    20. ...
    21. myTextObject = plainUi.myTextObject;
    22. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    codeslicer (23rd February 2008)

  4. #23
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: Still need help: Best way to have application "skins"?

    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!

  5. #24
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Still need help: Best way to have application "skins"?

    Quote Originally Posted by codeslicer View Post
    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:
    Qt Code:
    1. QPushButton* button = findChild<QPushButton*>("myButtonWithCertainObjectName");
    2. if (button) // just to assure it was found
    3. button->doSomething();
    4.  
    5. // or
    6.  
    7. QList<QPushButton*> allButtons = findChildren<QPushButton*>();
    8. foreach (QPushButton* button, allButtons)
    9. button->doSomething();
    To copy to clipboard, switch view to plain text mode 

    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.
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    codeslicer (24th February 2008)

  7. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Still need help: Best way to have application "skins"?

    Quote Originally Posted by codeslicer View Post
    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".

  8. #26
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation 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:
    Qt Code:
    1. void MyFancyWidget::setFancyMode()
    2. {
    3. myTextObject = fancyUi.myTextObject;
    4. myButtonObjectt = fancyUi.myButtonObject;
    5. }
    6.  
    7. void MyFancyWidget::setPlainMode()
    8. {
    9. ...
    10. myTextObject = plainUi.myTextObject;
    11. myButtonObject = plainUi.myButtonObject;
    12. }
    To copy to clipboard, switch view to plain text mode 

    I could use:
    Qt Code:
    1. for(int i=0; i<fancyUi.children().size(); i++) {
    2. childrenList[i]
    3. }
    To copy to clipboard, switch view to plain text mode 
    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?
    Qt Code:
    1. using namespace fancyUi
    To copy to clipboard, switch view to plain text mode 

    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!

  9. #27
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Still need help: Best way to have application "skins"?

    Quote Originally Posted by codeslicer View Post
    @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?

  10. #28
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation 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. ^

  11. #29
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

    Qt Code:
    1. class Base : public QWidget {
    2. //...
    3. };
    4.  
    5. class Plain : public Base, private Ui::BaseForm {
    6. //...
    7. };
    8.  
    9. class Fancy : public Base, private Ui::FancyForm {
    10. //...
    11. };
    12.  
    13. //...
    14.  
    15. Base *window = new Fancy(...);
    16. // or
    17. 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.

  12. The following user says thank you to wysota for this useful post:

    codeslicer (24th February 2008)

  13. #30
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face 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 So again, thanks for all this help, this forum is the best I've been on

  14. #31
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile 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:

    Qt Code:
    1. QLineEdit myLineEdit = *plainUi.myLineEdit;
    To copy to clipboard, switch view to plain text mode 

    or direct declarations:

    Qt Code:
    1. 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

  15. #32
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Still need help: Best way to have application "skins"?

    Quote Originally Posted by codeslicer View Post
    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?

    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

    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.

  16. The following user says thank you to wysota for this useful post:

    codeslicer (24th February 2008)

  17. #33
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: Still need help: Best way to have application "skins"?

    I kinda want to keep it a secret for now...

    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.

  18. #34
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Still need help: Best way to have application "skins"?

    Quote Originally Posted by codeslicer View Post
    I kinda want to keep it a secret for now...
    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.

  19. #35
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation 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...)
    Last edited by high_flyer; 27th February 2008 at 10:49. Reason: image removed due to poster request

  20. #36
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Attached Images Attached Images

  21. #37
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  22. #38
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Still need help: Best way to have application "skins"?

    Quote Originally Posted by codeslicer View Post
    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.

  23. The following user says thank you to wysota for this useful post:

    codeslicer (24th February 2008)

  24. #39
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  25. #40
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

Similar Threads

  1. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 19:37
  2. Application deployment problem
    By shapirlex in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 13th April 2007, 01:11
  3. Replies: 3
    Last Post: 8th December 2006, 19:51
  4. Replies: 3
    Last Post: 31st March 2006, 19:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.