how to change background color to imageView in javafx - javafx

I have a ImageView with a transparent image (PNG) therefore the image doesn't fill the complete rectangle of the image view, when mouse hover over the image view I want to change the background color of only the rectangle of the image view. In Css how I do it? do the image view node have the property -fx-background color? I tried and it's doesn't work for me.
I have a css file linked to the .FXML

Use this
Bounds bound = ImageView.getBoundsInLocal(); //getting co-ordinates
ImageView.setEffect(ColorInput(bound.getMinX(), bound.getMinY(),
bound.getWidth(), bound.getHeight(), Color.YELLOW));
By function should work.

Related

How to make translucent and ungeometrically shaped window in javafx?

Can somebody tell me how I can make translucent and ungeometrically shaped (any custom shape except geometric shapes like rectangle for ex- cloud shaped window) window in java fx. I tried it by setting the png image to the background of AnchorPane using css, but the whole AnchorPane is showing rectangular.

JavaFX: Set Background Color in TextFlow

I have a text flow widget in my JavaFx application for which I need to change the background color.
The layout is constructed using FXML, and the background color for the text flow needs to be set using external css file.
I'm able to set the background color for both textArea and textField, but unable to do so for textFlow.
Simply set the -fx-background-color property the same way you'd do it for other Regions e.g.:
TextFlow {
-fx-background-color: lightblue;
}

select a part of image with crosshair

I want to put a crosshair on an imageview.
Then, the user would be able to move crosshair on imageview and in another imageview, I want to see a part of main image around the center of crosshair.
for example if we have below image and we put crosshair on the position, i want to have the second image in another imageview.
how can i do it??
Main Image
The result that i want to have it in another imageview

How do I set the background position and size of a background image I set with setBackgroundBrush?

I used Qt's setBackgroundBrush function to set a background image. How do I resize the image or set it's position?
For example, I'd like it to be centered and for it to fill the entire region.
I don't think it's possible with setBackgroundBrush, but you can also set background image with style sheets if you want more control. Sample code from Qt docs:
QLabel {
background-image: url(dense6pattern.png);
background-repeat: repeat-xy;
}
More info available here.

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->setAutoFillBackground(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.

Resources