Results 1 to 5 of 5

Thread: How to get the native QStyle subclass?

  1. #1
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question How to get the native QStyle subclass?

    It must be really simple, but I can't figure it out:

    How do I create a QStyle object that contains the native look and feel of the computer I'm on?

    I basically want to write something like this:
    QStyle* pNativeStyle = QStyleFactory::createNativeStyle();
    ...but this method does not exist.

    By the time my code runs, the QApplication style has already been tinkered with, so I can't use QApplication::style().
    The QStyleFactory does not seem to have an option to simply create "the native style", whichever subclass of QStyle that is.


    How do I do it?

    Kind regards

    Robert

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get the native QStyle subclass?

    yes the style has been created but its not used until you allow it to.

    Qt Code:
    1. main()
    2. {
    3. QApplication app(argc,argv);
    4.  
    5. QStyle *nativeStyle = app.style();
    6. //do whatever you want to do with style;
    7.  
    8. //Style would be used now.
    9. mw.show();
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to get the native QStyle subclass?

    I'm inside a library that only gets called after the QApplication::style() has already been modified.

  4. #4
    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: How to get the native QStyle subclass?

    There is no such thing as a "native style". I'm on Linux, what's my "native style"? You can detect the operating system and based on that and Qt's source code you can check which style gets chosen by Qt by default. But there is no guarantee you are going to choose the right style since a particular style might not be available on a particular compilation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get the native QStyle subclass?

    If you want a new unmodified style what the default QApplication has selected on startup, try this.

    Qt Code:
    1. QStyle *s = app.style();
    2. qDebug() << s->objectName();
    3. QStyle *ns = QStyleFactory::create(s->objectName()); qDebug() << ns << ns->objectName();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 14th July 2011, 13:28
  2. Qt has wchar_t as non-native?
    By Wasabi in forum Newbie
    Replies: 7
    Last Post: 22nd December 2010, 21:08
  3. Replies: 8
    Last Post: 12th February 2010, 03:41
  4. using native kde-dialogs
    By #andi# in forum Newbie
    Replies: 2
    Last Post: 11th August 2009, 11:50
  5. Can Native Api be Used?
    By iGoo in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2006, 12:44

Tags for this Thread

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.