Results 1 to 11 of 11

Thread: Stylesheets and tiling images

  1. #1
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Stylesheets and tiling images

    hi guys!

    I have this next situation:

    I've created this button:



    And i want to increase the image size (width only) depending of the size of the button of course. But, tiling from the center part of the image. Lets see:



    In the example, I've added 10px in the middle, where the black rectangle mark is.

    I've tried with border-image... but with no luck, maybe i am doing it wrong.

    Any tip or idea of how to do this? Thanks.

    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Stylesheets and tiling images

    Perhaps attaching some code snippet of what you've done so far would bring some action to this thread...

    PS. Attach image files instead of linking to external sites, please.
    J-P Nurmi

  3. #3
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: Stylesheets and tiling images

    I just followed the tip on

    http://doc.trolltech.com/qq/qq20-qss...scalablestyles

    But i want only to tile the center part of the image. As you could see my buttons have same px on the middle (and has a gradient on left and right side). The height i need as it is, i just want to tile the width starting from the middle like i draft on those images.

    I am using common background-image for now... the thing is i don't want to use one image every different button size.

    Thanks.

    PS: yes i know, sorry... just in case my host being offline i am attaching the files.
    Attached Images Attached Images
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  4. #4
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: Stylesheets and tiling images

    Nobody guys/girls?

    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  5. #5
    Join Date
    Jan 2008
    Location
    Warsaw, Poland
    Posts
    26
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: Stylesheets and tiling images

    Quote Originally Posted by GuS View Post
    I've tried with border-image... but with no luck, maybe i am doing it wrong.
    Styling Qt Using Style Sheets <- here you can find few examples of border-image usage inspired by the CSS3 Draft Specification.
    Remember, border-image is drawn over background-image, but you don't need the latter here.

  6. #6
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: Stylesheets and tiling images

    Thanks, this was more clear even that in the CSS3 draft specification.

    So i did:

    Qt Code:
    1. border-image: url(:/Styles/styles/normalButton.png) 0 10 0 10 tile stretch;
    2. color: black; }
    To copy to clipboard, switch view to plain text mode 

    And now the image does not appears.

    The button size is 80px width (height is unchanged, cause I don't need to change it, only the width), so I need to maintain 8px as it is from the left and from right and only tile from the "middle". 8px is, 10% from each side.

    I don't know if i am doing it right.

    Thanks in advance.

    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  7. #7
    Join Date
    Jan 2008
    Location
    Warsaw, Poland
    Posts
    26
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: Stylesheets and tiling images

    Quote Originally Posted by GuS View Post
    The button size is 80px width (height is unchanged, cause I don't need to change it, only the width), so I need to maintain 8px as it is from the left and from right and only tile from the "middle". 8px is, 10% from each side.
    Numbers used in border-image correspond to image pixels, unless you put percent symbol next to them.
    Qt Code:
    1. border-width: 0px 8px 0px 8px;
    2. border-image: url(:/Styles/styles/normalButton.png) 0 8 0 8 stretch;
    3. color: black;
    4. }
    To copy to clipboard, switch view to plain text mode 
    Specifying border-width is important, because otherwise you'll see only the inner part.
    I hope that at last you have what you want.

    But... I don't know why this works correctly only with stretch, e.g. with round or tile inner part is not drawn and that's not the only problem (for interested testers: I've used Linux and Qt 4.3.2).

  8. #8
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: Stylesheets and tiling images

    Hi,

    This works... but i have a annoying dot line border on focus state but inside the button, there is a way to eliminate it? :S

    Have a look on the attached file.

    EDIT: maybe is stupid to continue post over this.. i know that is a minor problem... and many has other priority when develop an application. But i want to improve the style and even if Qt allows us to use StyleSheets. Just i want to use only one image for buttons of the same height... and not one image per button size... is why i keep trying to solve it.

    Thanks in advance.

    Cheers.
    Attached Images Attached Images
    Last edited by GuS; 9th February 2008 at 20:05.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  9. #9
    Join Date
    Jan 2008
    Location
    Warsaw, Poland
    Posts
    26
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: Stylesheets and tiling images

    Quote Originally Posted by GuS View Post
    This works... but i have a annoying dot line border on focus state but inside the button, there is a way to eliminate it? :S
    Focus rectangle is nothing weird here, it's standard thing, check non-styled QPushButton. It looks bad here, because you set only left and right border, so my suggestion is to change border-image to 8 8 8 8 and border-width appropriately.

    If you really want to completely remove this dotted rectangle, which is IMO a wrong idea (non-standard interface), there are 2 solutions:
    1. Worse - change focusPolicy to Qt::NoFocus (from Qt 4.3 you can do this in style sheet: qproperty-focusPolicy: NoFocus) - now button is inaccessible with keyboard.
    2. Better - subclass the style and reimplement drawControl() to strip out the State_HasFocus flag for the buttons - http://trolltech.org/developer/knowledgebase/743.
      However, if you use style sheets, drawControl() is never called with element equal to CE_PushButton, but CE_PushButtonBevel, which is useless. Maybe Qt Experts can voice on this behaviour. I'm relatively new to Qt, hence I cannot help you here.

  10. #10
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: Stylesheets and tiling images

    Yes, i know that the dotted border is normal behavior on focus action.
    Anyway, is not big problem, maybe Qt developers should add an "option" in stylesheet to have a way to disable it, or something similar inside the code, so we could avoid reimplementing QStyle only for that.

    Thanks for all!!

    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  11. #11
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Smile Re: Stylesheets and tiling images

    Well, since long time I've not continued this post.
    I was having anoying look of the border since i have a border-image with left and right about 8px of "padding". So, to have a normal dotted border (around the border image, like a normal behavior) i did this:

    QPushButton {
    color: black;
    border-image: url(:/Styles/styles/normalButton.png) 2 8 2 8 stretch stretch;
    border-width: 2px 8px 2px 8px;
    padding-left: -6px;
    padding-right: -6px;}
    Hope this help to someone

    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

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.