Results 1 to 9 of 9

Thread: how to apply stylesheet defined in .qss file to qt application

  1. #1
    Join Date
    Mar 2008
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to apply stylesheet defined in .qss file to qt application

    Hi,

    Can anyone pls tell me how to apply external stylesheet defined in a .qss file to a qt application? I'm using qt4.3

    I dont want to use command line switch "-stylesheet".


    Thanks in advance,
    Namita

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 apply stylesheet defined in .qss file to qt application

    Qt Code:
    1. QApplication app(...);
    2. QFile qss("stylesheet.qss");
    3. qss.open(QFile::ReadOnly);
    4. app.setStyleSheet(qss.readAll());
    5. qss.close();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2008
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to apply stylesheet defined in .qss file to qt application

    Hi,

    Thanks a lot...
    Now i'm able to apply external stylesheet to the qt application.


    Regards,
    Namita

  4. #4
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to apply stylesheet defined in .qss file to qt application

    Quote Originally Posted by namita View Post
    Hi,

    Thanks a lot...
    Now i'm able to apply external stylesheet to the qt application.


    Regards,
    Namita
    Hi. Im also using qss file. Are u adding Q_INIT_RESOURCES in ur main(), inorder to initialise qss?

    Thanx.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 apply stylesheet defined in .qss file to qt application

    QSS and Q_INIT_RESOURCES have nothing to do with each other.

  6. #6
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to apply stylesheet defined in .qss file to qt application

    Quote Originally Posted by wysota View Post
    QSS and Q_INIT_RESOURCES have nothing to do with each other.
    As far my understand I think qss(qt Style sheet) is also a resources and Q_INIT_RESOURCES is required to initialise all resources. So i asked this. I also posted this inforum http://www.qtcentre.org/forum/f-qt-p...rce-12508.html But i didnt get any reply. So i asked this.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 apply stylesheet defined in .qss file to qt application

    Quote Originally Posted by phillip_Qt View Post
    As far my understand I think qss(qt Style sheet) is also a resources
    That's not true.
    and Q_INIT_RESOURCES is required to initialise all resources.
    That's not true as well.

    "Qt resources" is a virtual filesystem, nothing more, nothing less. Stylesheets have nothing to do with files and in this particular case the stylesheet is loaded from an external and real file.

    Q_INIT_RESOURCES is only needed if you want to initialize resources that are embedded int a static library on some of the platforms. It' required to link them to the filesystem already existing in the application.

  8. #8
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to apply stylesheet defined in .qss file to qt application

    Quote Originally Posted by wysota View Post
    That's not true.

    That's not true as well.

    "Qt resources" is a virtual filesystem, nothing more, nothing less. Stylesheets have nothing to do with files and in this particular case the stylesheet is loaded from an external and real file.

    Q_INIT_RESOURCES is only needed if you want to initialize resources that are embedded int a static library on some of the platforms. It' required to link them to the filesystem already existing in the application.
    Thank you very much
    But i ve a doubt, can i use Q_INIT_RESOURCE macro in a dll.?
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 apply stylesheet defined in .qss file to qt application

    Do you need the macro? Yes, you can use it, but you probably don't have to.

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.