Results 1 to 10 of 10

Thread: QToolButton and StyleSheets.

  1. #1
    Join Date
    May 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QToolButton and StyleSheets.

    I'm using StyleSheets under QT 4.5 in my app, and most things work (aside from a few quirks)... but I haven't figured out how to get an icon loaded into a QToolButton derived class.

    in my c++ code:

    Qt Code:
    1. class myToolButton : public QToolButton
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. myToolButton ( QWidget *pParent = 0 ) : QToolButton(pParent) {}
    7. };
    To copy to clipboard, switch view to plain text mode 



    and my stylesheet css:
    Qt Code:
    1. myToolButton {
    2. border: none;
    3. min-height: 2px;
    4. min-width: 2px;
    5. width: 16px;
    6. height: 16px;
    7. icon-size: 13px, 13px;
    8. image : url (styles/cream/mybtn_up.png);
    9. }
    10. myToolButton:hover {
    11. image : url (styles/cream/mybtn_hover.png);
    12. }
    13. myToolButton:pressed{
    14. image : url (styles/cream/mybtn_pressed.png);
    15. }
    To copy to clipboard, switch view to plain text mode 


    but the images never show. Is it not possible to do this with QT StyleSheets yet? Or am I missing something?


    I'd really appreciate any help,

    steb.

  2. #2
    Join Date
    May 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QToolButton and StyleSheets.

    I found the issue. Relative paths aren't working for the derived class. It works only with absolute paths to the image....

    So I wrote a simple stylesheet pre-parser in my style loading method to parse all relative urls() and replace them with absolute paths (pre-pending the application base dir...)

    ...bug or feature?

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QToolButton and StyleSheets.

    Why dont you go the Qt way ,,, use resource files !!
    If you have the files in your resource file, you wont have to worry about the path much. Have a look at Qt Resource System in assistant

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QToolButton and StyleSheets.

    Quote Originally Posted by steb View Post
    I found the issue. Relative paths aren't working for the derived class. It works only with absolute paths to the image....

    So I wrote a simple stylesheet pre-parser in my style loading method to parse all relative urls() and replace them with absolute paths (pre-pending the application base dir...)

    ...bug or feature?
    there is no bug, relative path also works. the issue is that you've put space between "url" and right parenthesis..remove that and everything would work like magic!

  5. #5
    Join Date
    May 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QToolButton and StyleSheets.

    Quote Originally Posted by aamer4yu View Post
    Why dont you go the Qt way ,,, use resource files !!
    If you have the files in your resource file, you wont have to worry about the path much. Have a look at Qt Resource System in assistant
    the "Qt way"?
    Loading of stylesheets and external images at run-time is supported by QT... so I'm not sure I understand where you are coming from using this term.

    My goal was to allow my end-users to create/modify their own themes for the application.

    Anyways - as I mentioned above my themeing system now works fine with my pre-processor. This even allowed me to add support for some CSS3 features unsupported by QT such as @variables....

    Quote Originally Posted by talk2amulya View Post
    there is no bug, relative path also works. the issue is that you've put space between "url" and right parenthesis..remove that and everything would work like magic!
    actually, no spaces existed in the original stylesheet - if there were spaces between "url" and the first parenthesis it would have given a parsing error.
    The CSS sample code I posted above was just me paraphrasing the original code.

    This wasn't the bug I was seeing with derived classes & relative paths.

  6. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QToolButton and StyleSheets.

    Quote Originally Posted by steb View Post

    actually, no spaces existed in the original stylesheet - if there were spaces between "url" and the first parenthesis it would have given a parsing error.

    qt never gives any parsing error on CSS mind that..and it definitely works with relative paths if properly given. there is no such "bug"

  7. #7
    Join Date
    May 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QToolButton and StyleSheets.

    Quote Originally Posted by talk2amulya View Post
    qt never gives any parsing error on CSS mind that..and it definitely works with relative paths if properly given. there is no such "bug"
    I never said it "threw/raised" the parsing errors. It just fails ungracefully.

    There are bugs in QT's current CSS parsing.... lots of them.
    here's just one example:

    /*
    QSlider::vertical
    {
    /* background-image: url(images/mixer/mixer_slider_back.png); */
    border-width: 1;
    width : 50px;
    height : 170px;
    }
    */


    A CSS parser should ignore the above script (because the outer /* */ comment marker pair defines everything inside as a comment... regardless if there is another comment block within.

    QT fails to parse this correctly. It sees the first comment marker (/*) and matches it with the first comment close marker... instead of the second comment close marker.
    QT's parser obviously uses a simple internal flag to look for the matching comment close marker , instead of using a stack like system to match markers.

    QT also seems to have issues with properly cascading styles in certain cases. Such as the one I indicated in the original post.

  8. #8
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QToolButton and StyleSheets.

    Quote Originally Posted by steb View Post
    I never said it "threw/raised" the parsing errors. It just fails ungracefully.

    There are bugs in QT's current CSS parsing.... lots of them.
    here's just one example:

    /*
    QSlider::vertical
    {
    /* background-image: url(images/mixer/mixer_slider_back.png); */
    border-width: 1;
    width : 50px;
    height : 170px;
    }
    */


    A CSS parser should ignore the above script (because the outer /* */ comment marker pair defines everything inside as a comment... regardless if there is another comment block within.

    QT fails to parse this correctly. It sees the first comment marker (/*) and matches it with the first comment close marker... instead of the second comment close marker.
    QT's parser obviously uses a simple internal flag to look for the matching comment close marker , instead of using a stack like system to match markers.

    QT also seems to have issues with properly cascading styles in certain cases. Such as the one I indicated in the original post.
    You got a bad nested comment of /* */. Such nested comments are not allowed not just in CSS, but in C as well...

    If you want nested comment, use "//"

  9. #9
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QToolButton and StyleSheets.

    the "Qt way"?
    they mean to use Qt Resource System. You can then get rid of the relative paths, as it allows you to compile your resources into the exec file. Read about it in Assistant.
    /*
    QSlider::vertical
    {
    /* background-image: url(images/mixer/mixer_slider_back.png); */
    border-width: 1;
    width : 50px;
    height : 170px;
    }
    */
    Actually this code should not work in general, and for me it is quite normal that the first "/*" is matched with first "*/". That's the way it works.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  10. #10
    Join Date
    May 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QToolButton and StyleSheets.

    Quote Originally Posted by faldżip View Post
    they mean to use Qt Resource System. You can then get rid of the relative paths, as it allows you to compile your resources into the exec file. Read about it in Assistant.
    I know about the resource compiler. It's useless for a situation where I want my customers to be able to edit and create their own stylesheets/themes for loading as runtime....
    hence my use of external stylesheets that are loaded at runtime - not pre-compiled into the app.

    Quote Originally Posted by faldżip View Post
    Actually this code should not work in general, and for me it is quite normal that the first "/*" is matched with first "*/". That's the way it works.
    you're right. I just checked the CSS design specs. strange that nested comments are not supported in the spec, especially after so many years and several revisions.

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.