QPixmap::fill() usage



  • In constructor:
    @ setBackgroundRole(QPalette::Dark);
    setAutoFillBackground(true);
    @
    Refresh:
    @ pixmap.fill(palette().color(QPalette::Window)); // it should work, but it does not - the background is light gray
    pixmap.fill(QPalette::Window); // it should not work, palette().Window is ColorRole, not QColor, but it works
    @

    Also, the explanation on QPixmap::fill() is unclear:
    [quote]The effect of this function is undefined when the pixmap is being painted on.[/quote]
    What does this mean, the effect of the function is undefined when the pixmap is being painted on from another thread while this function is called, or what?



  • Hi,

    "The effect of this function is undefined when the pixmap is being painted on" means that if you paint on Pixmap, and your code do because you set setAutoFillBackground(true), a fill call could not work properly.

    QColor has a constructor that accept a Qt::GlobalColor enum; an enum is an integer value, then passing other integer QPalette::Window it works



  • Thank you for your answer.

    [quote author="mcosta" date="1367931408"]Hi,

    "The effect of this function is undefined when the pixmap is being painted on" means that if you paint on Pixmap, and your code do because you set setAutoFillBackground(true), a fill call could not work properly.[/quote]
    But I always want to paint something before or after I fill the background. This is the point with the background, it allows you to see the foreground. It makes no sense. Plus, this comes from an example. The example is in qt4, this is true, and QPixamp::fill() has changed in qt5, but still, it works.
    [quote author="mcosta" date="1367931408"]QColor has a constructor that accept a Qt::GlobalColor enum; an enum is an integer value, then passing other integer QPalette::Window it works [/quote]
    The QColor constructor story works, but enums are integers in C only, in C++ the compiler rejects the usage of a different enum type as argument of a function. Also, QPalette:Window is 10, like Qt::cyan. I would have noticed cyan instead of black.

    Why does
    @
    pixmap.fill(palette().color(QPalette::Window));@
    not work?



  • And this deserves a bump ... if anybody can explain these strange behaviors.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.