Results 1 to 2 of 2

Thread: Setting oxygen style on Qt applications

  1. #1
    Join Date
    Sep 2010
    Location
    Washington, PA
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Lightbulb Setting oxygen style on Qt applications

    This isn't a question, but more of a how-to that is probably pretty well known. However, I thought I would post something for if someone was looking for a way to set the "oxygen" style (aka KDE 4 style) on their Qt application.

    I was having problems viewing the oxygen style on my Windows Xming session, as it was defaulting to Bespin (yuck!). Clean-looks and Plastique were OK, but wanted the native oxygen look I was getting on my virtual machine. So this is what I came up with. I'm sure there might be another way around this, but it was easy enough for me to post it.

    I did NOT have an oxygen library in the $QTDIR/plugins/styles directory. I only had libbespin.so. However, since I am running KDE 4.4.5 on a Fedora 13 virtual box, I knew the oxygen style had to be somewhere. So after some searching, I found the oxygen library at /usr/lib/kde4/plugins/styles/oxygen.so. All I did to get the oxygen style on my Qt 4.6.3 application was to open up my CMakeLists.txt file and add:

    Qt Code:
    1. TARGET_LINK_LIBRARIES(qttest ${QT_LIBRARIES} /usr/lib/kde4/plugins/styles/oxygen.so)
    To copy to clipboard, switch view to plain text mode 

    This allowed me to link the oxygen shared object into my code. If you are using a straight g++ command-line, then you can do the "-l/usr/lib/kde4/plugins/styles/oxygen.so". Unfortunately, you are hard-coding this into the make system, but I wasn't looking at portability, but strictly for development purposes. At any rate, that is for another discussion.

    I then edited my main.cpp file (or wherever you are performing a "QApplication app(argc, argv)") and did this to it:

    Qt Code:
    1. #include <QApplication>
    2. #include <QStyleFactory>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7. QStyle *style = QStyleFactory::create("oxygen");
    8. if(style)
    9. {
    10. qDebug("Oxygen loaded!"); /// @note You can leave this out if you want!
    11. QApplication::setStyle(style);
    12. }
    13.  
    14. try
    15. {
    16. Anzo *anzo = new Anzo();
    17. anzo->show();
    18. return app.exec();
    19. }
    20. catch(std::exception &e)
    21. {
    22. std::cout<<"Exception: "<<e.what()<<std::endl;
    23. }
    24.  
    25. return -1;
    26. }
    To copy to clipboard, switch view to plain text mode 

    Note that the above code will not compile for you, but if you only do the QStyle portion, you should load oxygen in.

    I might be missing something, but this was a quick and dirty way for me to load the oxygen style into my Qt application.

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Posts
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting oxygen style on Qt applications

    This is very hackish and non portable (not only the path, but also the whole idea of linking to a plugin, you're not supposed to do that).

    QStyleFactory::create("oxygen") will find the oxygen plugin if you tell Qt where to look:
    export QT_PLUGIN_PATH=/usr/lib/kde4/plugins:$QT_PLUGIN_PATH

Similar Threads

  1. Qt 4.5 not using Oxygen style in some cases
    By pawelprazak in forum Newbie
    Replies: 1
    Last Post: 14th February 2009, 13:40
  2. Loading / setting custom style on win-xp
    By mpotocnik in forum Newbie
    Replies: 0
    Last Post: 29th April 2008, 11:38
  3. Setting a Style Issue
    By forrestfsu in forum Qt Programming
    Replies: 5
    Last Post: 28th March 2007, 21:32
  4. Replies: 1
    Last Post: 7th February 2007, 00:12
  5. Setting style in QApplication
    By Doug Broadwell in forum Newbie
    Replies: 2
    Last Post: 28th October 2006, 21:56

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.