QTextEdit and setStyle
I am trying to set a background image on a QTextEdit using setStyleSheet –
- textEdit->setStyleSheet(QString::fromUtf8("background-image: url(:/images/Chrysanthemum.png);background-attachment: fixed"));
However, this doe not work.
Am i misunderstanding the documentation or is it not possible?
Just out of curiousity have you tried this:
- textEdit->setStyleSheet("background-color: red);
and if that works fine try (of course your image file needs to be in the same dir as your sources then)
- textEdit->setStyleSheet("background-image: url(Chrysanthemum.png); background-attachment: fixed");
if that works too I’d guess something is wrong with your way of setting the file location.
Thats very strange indeed, because an example from the Qt Style Sheets Examples [qt-project.org] is pretty much the same
- background-color: white;
- background-image: url(draft.png);
- background-attachment: fixed;
My only guess is that somehow the file location is not correct. The bg.png file is located inside your source folder?
Here is my complete code, the image bg.png exists in the directory where the app is being run but is not set as the background
You had committed a silly mistake in adding the image to resource file. The prefix should had been “/” but it was “/images” in your case (it is also correct but) your folder containing the image was also named as “image”, so the address of image should have been “/images/images/bn.jpg”. It is working fine now. I have changed the prefix to “/” from “/images”. So now the valid address is “/images/bn.jpg”