Results 1 to 20 of 54

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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
    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:
    1. #include "ui_plainwidget.h"
    2. #include "ui_fancywidget.h"
    3.  
    4. class MyFancyWidget : public QWidget
    5. {
    6. ...
    7. private:
    8. Ui::FancyWidget fancyUi;
    9. Ui::PlainWidget plainUi;
    10. };
    11.  
    12. void MyFancyWidget::setFancyMode()
    13. {
    14. saveFormState(); // you might want to store contents if you let user to change mode on the fly
    15. qDeleteAll(children()); // or something like this to clear everything, it is important to delete layout()
    16. fancyUi.setupUi(this);
    17. restoreFormState(); // restore contents
    18. }
    19.  
    20. void MyFancyWidget::setPlainMode()
    21. {
    22. ...
    23. plainUi.setupUi(this);
    24. ...
    25. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    codeslicer (23rd February 2008)

  3. #2
    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!

  4. #3
    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

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

    codeslicer (23rd February 2008)

  6. #4
    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!

  7. #5
    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

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

    codeslicer (24th February 2008)

  9. #6
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

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

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

Similar Threads

  1. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37
  2. Application deployment problem
    By shapirlex in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 13th April 2007, 00:11
  3. Replies: 3
    Last Post: 8th December 2006, 18:51
  4. Replies: 3
    Last Post: 31st March 2006, 18: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.