开发者

Update color of an image or Background color of Image

I am making Image Editor App.I want to add QColorDialog for update Color of image. I have set image on QLabel.

This is my code that run fine but not able to change color of image.

void ImageViewer::updateColor()
{
    QColor color = QColorDialog::getColor(Qt::white,ui->imageHolder);

    if(color.isValid())
    {
//        QPixmap pixmap = *ui->imageHolder->pixmap();  
//        pixmap.fill(color);**  //this is also not change color of image  
        ui->imageHolder->setPalette(QPalette(color));  
        ui->imageHolder->setAuto开发者_开发问答FillBackground(true);  
        ui->imageHolder->update();  
    }  
}

I have no idea how to change color of image or backbround color of that image... is it posible?

Any idea?

Thanks...


What is the type of your imageHolder widget ?

I would recommend using Qt Style Sheet to change the background color of a widget.

As Qt documentation states :

Using a QPalette isn't guaranteed to work for all styles, because style authors are restricted by the different platforms' guidelines and by the native theme engine.

To change the background color of your widget (there might be some restriction depending on the type of imageHolder), here is what you could do something like this :

ui->imageHolder->setStyleSheet("background-color : " + color.name());


If you are trying to change the pixel values of the image QPalette is not what you think it is for. It's for changing the colors of the UI elements.

If the background color is all you want to change, QPalette can do the job but you will need a image that contains alpha channel or transparency mask. Load a PNG with alpha into your image holder and see if that works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜