Results 1 to 4 of 4

Thread: Using .svg images for QPushButton Style sheets

  1. #1
    Join Date
    Jun 2011
    Posts
    19
    Thanks
    3

    Default Using .svg images for QPushButton Style sheets

    I'm tying to use scalable vector graphics for my push button, except two main issues arise when doing so:


    0) when setting the push button to the svg, it seems centered on the top left corner for some strange reason
    1) when trying to set a mask using the pixmap, it seems that the svg does not scale right at all to the box

    this i my svg
    Qt Code:
    1. <?xml version="1.0"?>
    2. <svg xmlns="http://www.w3.org/2000/svg" width="12cm" height="12cm">
    3. <g style="fill-opacity:0.7; stroke:black; stroke-width:0.1cm;">
    4. <circle cx="6cm" cy="2cm" r="100" style="fill:red;"
    5. transform="translate(0,50)" />
    6. <circle cx="6cm" cy="2cm" r="100" style="fill:blue;"
    7. transform="translate(70,150)" />
    8. <circle cx="6cm" cy="2cm" r="100" style="fill:green;"
    9. transform="translate(-70,150)"/>
    10. </g>
    11. </svg>
    To copy to clipboard, switch view to plain text mode 

    and here is my style sheets

    Qt Code:
    1. QPushButton:enabled{
    2. border-image: url(:/Button1/img1.svg) 4 4 4 4 stretch stretch;
    3. }
    To copy to clipboard, switch view to plain text mode 

    here is my masking method

    Qt Code:
    1. QPixmap pixmap(":/Button1/img1.svg");
    2. ui->pushButton->setMask(pixmap.mask());
    To copy to clipboard, switch view to plain text mode 


    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using .svg images for QPushButton Style sheets

    1) when trying to set a mask using the pixmap, it seems that the svg does not scale right at all to the box
    You have to scale your pixmap to the right size before setting the mask.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jun 2011
    Posts
    19
    Thanks
    3

    Default Re: Using .svg images for QPushButton Style sheets

    how does one scale the pixmap?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using .svg images for QPushButton Style sheets

    Did you try QPixmap::scaled()?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Style Sheets
    By yakuzan in forum Newbie
    Replies: 5
    Last Post: 29th May 2010, 09:11
  2. Do Qt Style Sheets support List-style-image?
    By daiheitan in forum Qt Programming
    Replies: 6
    Last Post: 12th March 2010, 01:41
  3. BG image on QPushButton using style sheets??
    By JimDaniel in forum Newbie
    Replies: 2
    Last Post: 13th September 2007, 03:31
  4. Qt style sheets
    By locus in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2007, 17:03
  5. style sheets
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2007, 15:14

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.