QTextEdit and setStyle
-
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":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-specific-widgets is pretty much the same
@
QTextEdit, QListView {
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?
-
OK
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
@#include <QtGui>int main(int argc, char **argv)
{
QApplication app(argc, argv);QTextEdit* edit = new QTextEdit(); edit->setWindowTitle("QTextEdit Background Image"); edit->setStyleSheet("background-image: url(bg.png)"); edit->show(); return app.exec();
}@
-
-
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"