Results 1 to 5 of 5

Thread: Getting the name of the default style

  1. #1
    Join Date
    Mar 2008
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Getting the name of the default style

    Hi,

    I have a question regarding the default style name for a given operating system.

    I would like to show in my app a combobox with all valid styles (which I can get using QStyleFactory.keys()) and select the style that is the default one for the operating system on which the app is run.

    How do I get the default style name?

    I already tried the QSettings("Trolltech").value("style"), but the string that I got is empty.

    If it's important, I'm using Qt 4.3.3 thru PyQt.

    Thanks in advance for the answer...

  2. #2
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Getting the name of the default style

    You mean style Name: Motif/CDE/ etc ?

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  3. #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: Getting the name of the default style

    In C++ it would be:
    Qt Code:
    1. QString styleName = QApplication::style()->objectName();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. The following 2 users say thank you to jpn for this useful post:

    gregsan (27th March 2008), maverick_pol (27th March 2008)

  5. #4
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting the name of the default style

    It is an old thread but nevertheless interesting for my identical task.

    There is one thing that does not work for me (Qt 4.7.4):
    What jpn suggests return the current style of the application.
    But I need the default style an application gets if the style is not manually changed. On WinXP it should return "WindowsXP", on Vista it should return something like "WindowsVista" (I assume).

    I need this for configuring my application to "system default style" instead of a manually selected style like WindowsXP, Cleanlooks or...

  6. #5
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting the name of the default style

    (Edit of my previous post is not possible, so this "double post")

    What I am doing now to get the "default style" is to ask the QApplication object right after application start for its style before applying a different style.
    Qt Code:
    1. QString defaultStyleName = qApp->style()->objectName();
    2. qApp->setStyle(/*e.g. Plastique style*/);
    3.  
    4. // much more code follows and later I want to switch to the default style:
    5. qApp->setStyle(QStyleFactory::create(defaultStyleName));
    To copy to clipboard, switch view to plain text mode 
    But this approach fails if someone start teh application with the commandline option -style=<someStyle>. Then my defaultStyleName string would be <someStyle> and NOT the default style Qt uses for the underlaying operating system.

    How can the system's default style be determined?

Similar Threads

  1. style sheets select all except something
    By codeslicer in forum Qt Programming
    Replies: 4
    Last Post: 6th March 2008, 00:21
  2. QToolButton and Style sheet
    By desch in forum Qt Programming
    Replies: 8
    Last Post: 1st December 2007, 08:38
  3. Qt 4.3 Style sheet, new features
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2007, 15:22
  4. Setting a Style Issue
    By forrestfsu in forum Qt Programming
    Replies: 5
    Last Post: 28th March 2007, 21:32
  5. about scrollbar style
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 13:34

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.