Results 1 to 6 of 6

Thread: Style Sheets: re-using/referencing builtin pixmaps

  1. #1
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Style Sheets: re-using/referencing builtin pixmaps

    I'm trying to create a style sheet that uses one of the builtin icons (http://doc.trolltech.com/4.4/stylesh...#list-of-icons)

    I really want to reference the 'downarrow-icon' but I'm not sure if there is a syntax available to support it.

    Off the bat I tried using Qt's documentation for help and tried this:

    QFooBar {
    image: url(downarrow-icon);
    }

    It works fine when you give it a path in the resource system just not a builtin icon.

    ex. works:
    QFooBar {
    image: url(:myIcon.png);
    }

    Any ideas?

  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: Style Sheets: re-using/referencing builtin pixmaps

    It's not like that. It works the other way. The mechanism is made available so that you can substitute one of the predefined images (like "downarrow-icon") with your own. So the syntax would be:
    css Code:
    1. something {
    2. downarrow-icon: url(:/myicon.png);
    3. }
    To copy to clipboard, switch view to plain text mode 
    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.


  3. #3
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: Style Sheets: re-using/referencing builtin pixmaps

    Yeah I was afraid of that. Its certainly a shame you can't reference builtin icons. It could be a powerful tool for custom widgets. I'm a fan of keeping a consistent look and feel and using builtin icons and system icons are something that Qt seems to be missing.

    Though with Qt 4.5 it appears we can now use some system icons (I've yet to play with it since I'm still waiting on PyQt 4.5 to be released)

  4. #4
    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: Style Sheets: re-using/referencing builtin pixmaps

    Quote Originally Posted by chezifresh View Post
    Yeah I was afraid of that. Its certainly a shame you can't reference builtin icons.
    Sure you can. It's a bit more complicated but certainly possible. Qt allows you to create artificial file systems (like the resource file system) where you can add whatever data you want. Standard pixmaps included.

    And if you don't have to use stylesheets, you can reference the icons directly using QStyle API.
    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 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: Style Sheets: re-using/referencing builtin pixmaps

    Absolutely, I was just hoping I could pull it off in a stylesheet. My specific use case for this is that I'm building a QTreeView that has combo boxes as persistent widgets. I want the combo boxes to be clear with no borders (basically just showing the text and the down arrow).

    I bit this off by using the stylesheet to make the borders and backgrounds transparent. The down side is that there seems to be a bug in the QComboBox::drop-down if you set the stylesheet on it you lose the indicator. So I'm re-applying the indicator with a neutral color pixmap (to work with dark/light color schemes). So this conversation really came about because of quirk in the stylesheet. I can probably accomplish this much better by subclassing the combo box, I was just looking for something quick and dirty for the time being and ran into this.

    Thanks for your help though, its good to know this isn't supported through stylesheets

  6. #6
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Style Sheets: re-using/referencing builtin pixmaps

    I found this on one of the three main Stylesheets reference pages:

    Note: With complex widgets such as QComboBox and QScrollBar, if one property or sub-control is customized, all the other properties or sub-controls must be customized as well.

    This might explain why your arrow disappeared when you customized part of the combobox but you may have already known the nature of the quirk.

    Fastest way I can think of would be to programmatically save out the icons you want via the non-static QStyle::standardIcon(QStyle::SP_ArrowDown), etc. With those image files on your drive, you can compile an external Resource that your stylesheets can access at runtime (assuming the resource syntax holds for stylesheets).

    You may not be able to drop those "SP_" enums right into the stylesheet code but "url(:/qtStandard/downArrow)" seems reasonable.

Similar Threads

  1. Performace problem with style sheets
    By Cruz in forum Qt Programming
    Replies: 0
    Last Post: 7th February 2009, 13:20
  2. Replies: 2
    Last Post: 5th July 2008, 19:35
  3. [CSS] variables in style sheets?
    By Boy in forum Qt Programming
    Replies: 0
    Last Post: 22nd May 2008, 10:34
  4. style sheets select all except something
    By codeslicer in forum Qt Programming
    Replies: 4
    Last Post: 6th March 2008, 00:21
  5. Qt style sheets
    By locus in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2007, 17:03

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.