Results 1 to 3 of 3

Thread: Using QWidget::setMask(...) to create non rectangular custom push buttons

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

    Default Using QWidget::setMask(...) to create non rectangular custom push buttons

    I Have been using the style sheets to edit custom states to make my own push button.

    How can you use the setMask() feature to hide out the alpha areas of the picture used in the push button so when you click on a transparent area it does not set off the click?

    Thanks!

    heres my style sheet

    Qt Code:
    1. QPushButton:enabled{
    2. border-image: url(:/Button1/triangle.png) 4 4 4 4 stretch stretch;
    3. }
    4.  
    5. border-image: url(:/Button1/normal.png) 4 4 4 4 stretch stretch;
    6. }
    7.  
    8. QPushButton:pressed {
    9. border-image: url(:/Button1/pressed.png) 4 4 4 4 stretch stretch;
    10. }
    To copy to clipboard, switch view to plain text mode 

    and this was what i tried in order to make the triangle alpha areas work, (to no success)
    Qt Code:
    1. QPixmap pixmap(":/Button1/triangle.png");
    2. ui->pushButton->setMask(pixmap.mask());
    To copy to clipboard, switch view to plain text mode 

    I am aware that I could also create my own custom class which inherits from QLabel that recognizes clicks, however I'm still not too sure how to mask certain things


    Help would be appreciated!
    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 QWidget::setMask(...) to create non rectangular custom push buttons

    Qt Code:
    1. QPixmap pixmap(":/Button1/triangle.png");
    2. ui->pushButton->setMask(pixmap.mask());
    To copy to clipboard, switch view to plain text mode 
    This code looks ok to me.
    Are you sure the transparent areas in your png are really alpha=0? maybe its not 100% transparent?
    ==========================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 QWidget::setMask(...) to create non rectangular custom push buttons

    It seems the error was not #include <QBitmap>

    thanks!

Similar Threads

  1. Replies: 2
    Last Post: 16th May 2011, 00:15
  2. QWidget setMask fully transparent.
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 6th August 2009, 13:30
  3. QWidget::setMask: bug &/or help for workaround
    By ataffard in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2008, 07:34
  4. Replies: 1
    Last Post: 19th May 2007, 05:19
  5. QPixmap::setMask() / QWidget::setMask()
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 25th February 2006, 11:34

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.