Results 1 to 5 of 5

Thread: Alpha color and irregular form widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Alpha color and irregular form widget

    Hi, I need to write a program similar to XTeddy, portable, I make the image to be showed and I can move it with the mouse, but it appear in a rectancle that ignore the alpha color.

    Some idea of how to set the region of the widget only to the non alpha zone of the image?

    Thanks

    PD: sorry for my bad english

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Alpha color and irregular form widget

    Take a look at QWidget::setMask.

  3. The following user says thank you to wysota for this useful post:

    sshd (27th February 2008)

  4. #3
    Join Date
    Feb 2008
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Alpha color and irregular form widget

    I have a problem again, with the function

    Qt Code:
    1. void CarmenTiger::paintEvent(QPaintEvent *) {
    2. QPainter painter(this);
    3. QPointF point;
    4. const QImage image = QImage("tiger.png");
    5.  
    6. painter.setBackgroundMode(Qt::TransparentMode);
    7. painter.setRenderHint(QPainter::Antialiasing);
    8. painter.drawImage(point, image);
    9. } // paintEvent
    To copy to clipboard, switch view to plain text mode 

    the program draw the image over a rectangle and using the function

    Qt Code:
    1. void CarmenTiger::paintEvent(QPaintEvent *) {
    2. QLabel topLevelLabel;
    3. QPixmap pixmap(":/tiger.png");
    4.  
    5. topLevelLabel.setPixmap(pixmap);
    6. topLevelLabel.setMask(pixmap.mask());
    7. } // paintEvent
    To copy to clipboard, switch view to plain text mode 

    the program draw only the rectangle.

    Any idea of what is wrong?
    Last edited by jpn; 28th February 2008 at 18:53. Reason: missing [code] tags

  5. #4
    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: Alpha color and irregular form widget

    You don't want to
    • instantiate a QLabel object (you create a label, set a pixmap, and the object is immediately destructed after paintEvent() reaches its end)
    • apply the mask (which is an expensive operation especially if the mask is complex)

    during every paint event.
    J-P Nurmi

  6. #5
    Join Date
    Feb 2008
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Alpha color and irregular form widget

    OK, I understand the problem, but I have no idea of how fix it, what I have to modify, something in the main.cpp, the constructor, the paintEvent or I have to write another function?

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
  •  
Qt is a trademark of The Qt Company.