Results 1 to 17 of 17

Thread: QT 4.2 widget setmask problem

  1. #1
    Join Date
    Feb 2007
    Posts
    28
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QT 4.2 widget setmask problem

    Hi all,
    Hope someone can help.
    I develop my application main widget so it have transparent edges, by following the TUX example.
    This work perfectly in QT 4.1.
    But now i move to QT 4.2 and does not work anymore, all the borders come black, and its look like the widget mask is not been applied.
    Any info on this?
    What can i do???
    Any help will be much appreciated
    Thanks
    CJC.

  2. #2
    Join Date
    Jan 2006
    Location
    Cambridge, MA
    Posts
    32
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QT 4.2 widget setmask problem

    Can you post some code you are using?

  3. #3
    Join Date
    Feb 2007
    Posts
    28
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QT 4.2 widget setmask problem

    Sure, this is basically my code.

    Qt Code:
    1. QPixmap pixmap("transparentImage.png");
    2. QImage image("transparentImage.png");
    3. QBitmap bt();
    4.  
    5.  
    6.  
    7. //Create the mask
    8. image = image.createAlphaMask(Qt::AutoColor);
    9.  
    10.  
    11. bt= QBitmap::fromImage(image,Qt::AutoColor);
    12. pixmap.setMask(bt);
    13.  
    14.  
    15.  
    16. //Aply the mask to the widget
    17. _mainWidget->setMask(pixmap.mask());
    To copy to clipboard, switch view to plain text mode 

    The result in qt 4.1 is that the mask is applied to the mainwidget and the transparent pixel in the image come clipped.
    The result in qt 4.2 is that the transparent pixels in the image are black, and looks like the mask is not been applied

    Any help plz
    THanks
    CJC

  4. #4
    Join Date
    Feb 2007
    Posts
    28
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QT 4.2 widget setmask problem

    Any help on this plz

  5. #5
    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: QT 4.2 widget setmask problem

    I thought it was something as simple as this when the image had transparent edges:
    Qt Code:
    1. QPixmap pixmap("transparentImage.png");
    2. _mainWidget->setMask(pixmap.mask());
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. #6
    Join Date
    Feb 2007
    Posts
    28
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QT 4.2 widget setmask problem

    Me too, but it didnt work.
    So I try to do it like the tux example and it work very good in qt 4.1 but in qt 4.2 now dont work.
    Any more help on this?
    Maybe someone has a workarround or and example that work in qt 4.2?
    Thanks
    CJC!

  7. #7
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT 4.2 widget setmask problem

    Quote Originally Posted by PiXeL16 View Post
    Me too, but it didnt work.
    So I try to do it like the tux example and it work very good in qt 4.1 but in qt 4.2 now dont work.
    Any more help on this?
    Maybe someone has a workarround or and example that work in qt 4.2?
    Have you checked the Tux example in Qt 4.2???
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #8
    Join Date
    Feb 2007
    Posts
    28
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QT 4.2 widget setmask problem

    The problem is that the TUX example is not included.
    Even in qt 4.1 it was not included. I need to work with the old example i think from qt 3 and change all the not working and old functions.
    Any way, someone has and example of this or maybe some workaround to make this work?
    Please, any help will be much appreciated.
    Thanks
    CJC

  9. #9
    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: QT 4.2 widget setmask problem

    I'm using Qt 4.2.2 on X11 and it works for me the simple way I described.. Doesn't the attached example work for you?
    Attached Images Attached Images
    Attached Files Attached Files
    J-P Nurmi

  10. #10
    Join Date
    Feb 2007
    Posts
    28
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QT 4.2 widget setmask problem

    Thanks,
    Yeah thats the effect that i want to give.
    Maybe is because im using a dialog? and you are using a label?
    Or also, im using a qpainter to create the image. maybe something change from qt 4.1 to qt 4.2 and the qpainter draw images does not create transparent parts?

    Thanks
    CJC

  11. #11
    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: QT 4.2 widget setmask problem

    Quote Originally Posted by PiXeL16 View Post
    Maybe is because im using a dialog? and you are using a label?
    That should not have effect of any kind. Both are QWidgets.

    Or also, im using a qpainter to create the image. maybe something change from qt 4.1 to qt 4.2 and the qpainter draw images does not create transparent parts?
    Try filling the image with a transparent color before painting the shape.
    J-P Nurmi

  12. #12
    Join Date
    Jan 2006
    Location
    Cambridge, MA
    Posts
    32
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QT 4.2 widget setmask problem

    Quote Originally Posted by PiXeL16 View Post
    Sure, this is basically my code.

    Qt Code:
    1. QPixmap pixmap("transparentImage.png");
    2. QImage image("transparentImage.png");
    3. QBitmap bt();
    4.  
    5.  
    6.  
    7. //Create the mask
    8. image = image.createAlphaMask(Qt::AutoColor);
    9.  
    10.  
    11. bt= QBitmap::fromImage(image,Qt::AutoColor);
    12. pixmap.setMask(bt);
    13.  
    14.  
    15.  
    16. //Aply the mask to the widget
    17. _mainWidget->setMask(pixmap.mask());
    To copy to clipboard, switch view to plain text mode 

    The result in qt 4.1 is that the mask is applied to the mainwidget and the transparent pixel in the image come clipped.
    The result in qt 4.2 is that the transparent pixels in the image are black, and looks like the mask is not been applied
    This looks reasonable. Have you thought that maybe your app isn't finding transparentImage.png. I notice a relative path here. Try using the qt resource system to embed your images into the executable.

    --Justin

  13. #13
    Join Date
    Feb 2007
    Posts
    28
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QT 4.2 widget setmask problem

    Hi thanks for the reply.
    No, that was an example. Im using a qrc resource file, and the app is finding the image correctly.
    Also, im using a qpainter to create a big image from small image. The qpainter default color is transparent, so i dont have to do that according to QT.
    Anyway, i try setting a transparent color with no luck.
    Anything that i could be missing here?

  14. #14
    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: QT 4.2 widget setmask problem

    Quote Originally Posted by PiXeL16 View Post
    Also, im using a qpainter to create a big image from small image.
    How about scaling?

    The qpainter default color is transparent, so i dont have to do that according to QT.
    Yes, but QPixmap might not be. As you said, a new QPixmap is constructed. What I actually meant was filling that pixmap with transparent color.
    J-P Nurmi

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

    Default Re: QT 4.2 widget setmask problem

    You could be using some window flags that cause the problem. Could we see the _mainWidget constructor and the way you call it?

  16. #16
    Join Date
    Feb 2007
    Posts
    28
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QT 4.2 widget setmask problem

    Hi, thanks for the reply
    What i mean by creating an image with small images is that i'm creating and pixmap using small various pixmap. So i cant use scaling.
    I'm going to try your idea of filling the pixmap first with transparent color. Maybe that work.
    Also, about the flags, i'm just basically using a frameless flag. like this.

    Qt Code:
    1. Qt::WindowFlags flags = 0;
    2. flags = Qt::FramelessWindowHint;
    3. _mainWidget->setWindowFlags(flags);
    To copy to clipboard, switch view to plain text mode 

    Could something change in the way qt manage transparent colors from qt 4.1 to 4.2?
    Thanks
    Any help will be much appreciated
    CJC

  17. #17
    Join Date
    Feb 2007
    Posts
    28
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QT 4.2 widget setmask problem

    I forget, im calling it with the show function
    like this

    Qt Code:
    1. _mainWidget->show();
    To copy to clipboard, switch view to plain text mode 

    Thanks
    CJC

Similar Threads

  1. QDockWidget/Central Widget Problem
    By Lemming in forum Qt Programming
    Replies: 7
    Last Post: 3rd April 2016, 09:52
  2. Problem applying setWindowOpacity to a custom Widget
    By yellowmat in forum Qt Programming
    Replies: 8
    Last Post: 1st November 2006, 10:05
  3. Replies: 3
    Last Post: 12th April 2006, 08:20
  4. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 08:12
  5. Replies: 7
    Last Post: 3rd February 2006, 10:20

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.