Results 1 to 6 of 6

Thread: Qt style sheets

  1. #1
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt style sheets

    I am trying to implement a feature in y application where the user can change the face of the GUI by choosing from a list of styles.

    Each option should apply a different style sheet to the application.

    Questions:

    Can i arbitrarily just add styles to application while it runs, as described above?

    and more importatntly

    Could anyone give me some pointers on how to go about saving the style settings of the application.

    I am already using QSettings to save the geometry and position of the main window, along with some other options, but i don't see a way to save the style sheet options yet.

    all sugstions welcomed.

    Thanks for your response.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt style sheets

    Quote Originally Posted by locus View Post
    I am trying to implement a feature in y application where the user can change the face of the GUI by choosing from a list of styles.

    Each option should apply a different style sheet to the application.

    Questions:

    Can i arbitrarily just add styles to application while it runs, as described above?

    and more importatntly

    Could anyone give me some pointers on how to go about saving the style settings of the application.

    I am already using QSettings to save the geometry and position of the main window, along with some other options, but i don't see a way to save the style sheet options yet.

    all sugstions welcomed.

    Thanks for your response.


    just tested tody on window && ubuntu linux ...

    on main.cpp to

    QSettings setter;
    QString soko = QString(setter.value("WinStyle").toString());
    and load the style ...


    Qt Code:
    1. #include "arthurstyle.h" /* not work on QWorkspace */
    2. #include "arthurwidgets.h"
    3. #include "norwegianwoodstyle.h"
    4. #if defined Q_WS_WIN
    5. #include <QWindowsXPStyle>
    6. #include <QWindowsVistaStyle>
    7. #endif
    8.  
    9. void Gui_Main::ModStyle()
    10. {
    11. QStringList items = QStyleFactory::keys(); /* incomming list supported on all os */
    12. items.append("QWindowsVistaStyle");
    13. #ifdef QT_OPENGL_SUPPORT
    14. items.append("ArthurStyle");
    15. #endif
    16. items.append("NorwegianWood");
    17. bool ok = false;
    18. QString soko = QInputDialog::getItem(0,"Select style name.",
    19. "Style:", items, 0, false, &ok);
    20.  
    21. if (ok) {
    22. setter.setValue("WinStyle",soko);
    23.  
    24. if (soko.size() > 0 ) {
    25. if (soko == "NorwegianWood") {
    26. QApplication::setStyle(new NorwegianWoodStyle);
    27. } else if (soko == "QWindowsVistaStyle") {
    28. #if defined Q_WS_WIN
    29. QApplication::setStyle(new QWindowsVistaStyle);
    30. #endif
    31. } else if (soko == "ArthurStyle") {
    32. #ifdef QT_OPENGL_SUPPORT
    33. QStyle *arthurStyle = new ArthurStyle();
    34. QList<QWidget *> widgets = qFindChildren<QWidget *>(this);
    35. foreach (QWidget *w, widgets) {
    36. w->setStyle(arthurStyle);
    37. }
    38. QApplication::setStyle(arthurStyle);
    39. #endif
    40. } else {
    41. QApplication::setStyle(QStyleFactory::create(soko));
    42. }
    43. ///////////QApplication::setPalette(QApplication::style()->standardPalette());
    44. }
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    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: Qt style sheets

    You may apply stylesheets whenever you want.

  4. #4
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt style sheets

    to each widget? or globally to the whole application?

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt style sheets

    Quote Originally Posted by elcuco View Post
    to each widget? or globally to the whole application?
    QApplication is the top class ...
    after the command ....
    QApplication::setStyle(arthurStylexxxxx);
    the style is visible....

    i save to qsetting and edit at mainwindow...


    on main..... load the style and all other xxx
    Qt Code:
    1. int main(int argc, char *argv[]) {
    2.  
    3. QApplication a( argc, argv );
    4. QCoreApplication::setOrganizationName(_ORGANIZATION_NAME_);
    5. QCoreApplication::setOrganizationDomain(_PROGRAM_NAME_DOMAINE_);
    6. QCoreApplication::setApplicationName(_PROGRAM_NAME_);
    7.  
    8. QString localedirfile;
    9.  
    10. #if defined Q_WS_MAC
    11. localedirfile = QString("%1/locale/edit_%2.qm").arg(WORK_CACHEDIR).arg(UserLanguage());
    12. #endif
    13. #if defined Q_WS_WIN
    14. localedirfile = QString("%1/locale/edit_%2.qm").arg(QCoreApplication::applicationDirPath()).arg(UserLanguage());
    15. #endif
    16. #if defined Q_WS_X11
    17. localedirfile = QString("%1/locale/edit_%2.qm").arg(WORK_CACHEDIR).arg(UserLanguage());
    18. #endif
    19. QTranslator translator;
    20. translator.load(localedirfile);
    21. a.installTranslator(&translator);
    22.  
    23. if (!NetworkEnable()) {
    24. QMessageBox::warning(0,"NetworkInterface","Check Your Network! SQL DB get data........");
    25. return 0;
    26. }
    27.  
    28. Preload *splash = new Preload(1400,LICENCE); /* animated painter dialog widget loading msec */
    29. splash->exec();
    30.  
    31. QSettings setter;
    32. QString soko = QString(setter.value("WinStyle").toString());
    33. Gui_Main::self()->setWindowTitle( _PROGRAM_TITLE_ );
    34.  
    35. if (soko.size() > 0 ) {
    36. if (soko == "NorwegianWood") {
    37.  
    38. a.setStyle(new NorwegianWoodStyle);
    39.  
    40. } else if (soko == "ArthurStyle") {
    41. #ifdef QT_OPENGL_SUPPORT
    42. QStyle *arthurStyle = new ArthurStyle();
    43. QList<QWidget *> widgets = qFindChildren<QWidget *>(Gui_Main::self());
    44. foreach (QWidget *w, widgets) {
    45. w->setStyle(arthurStyle);
    46. }
    47. a.setStyle(arthurStyle);
    48. #endif
    49. } else if (soko == "QWindowsVistaStyle") {
    50.  
    51. #if defined Q_WS_WIN
    52. a.setStyle(new QWindowsVistaStyle);
    53. #endif
    54.  
    55. } else {
    56. a.setStyle(QStyleFactory::create(soko));
    57. }
    58.  
    59. ///////////a.setPalette(QApplication::style()->standardPalette());
    60. }
    61. QString argument_1;
    62. argument_1 = QString::fromLatin1(argv[1]);
    63. if (argument_1.contains(".chre")) {
    64. Gui_Main::self()->setOpen(QUrl(argument_1));
    65. }
    66. Gui_Main::self()->show();
    67. ///////// splash self close /////
    68. a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    69. return a.exec();
    70. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by patrik08; 4th April 2007 at 02:43.

  6. #6
    Join Date
    Aug 2006
    Posts
    44
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt style sheets

    Quote Originally Posted by elcuco View Post
    to each widget? or globally to the whole application?
    In the Overview section of the QStyleSheet docs, it's pretty clear that at any point in a widget hierarchy, you can call QWidget::setStyleSheet(). So, for that widget and its children, the style applies. If you modify the styles on a child of widget A, say, in A', then A' and its children get the new style, etc.

    Hope this helps.

Similar Threads

  1. style sheets
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2007, 16:14
  2. Setting a Style Issue
    By forrestfsu in forum Qt Programming
    Replies: 5
    Last Post: 28th March 2007, 22:32
  3. about scrollbar style
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 14:34
  4. Qt Style Sheets Problems with QDialog
    By Lykurg in forum Qt Programming
    Replies: 3
    Last Post: 5th November 2006, 15:43
  5. Bugs, style changes in 4.1.0?
    By simk in forum Qt Programming
    Replies: 13
    Last Post: 13th February 2006, 12:05

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.