QT5.15.2 No background image from QPixmap
-
I have a couple of
QLineEditwidgets and want to have a background image. I've found a lot of examples showing this with a CSS (setStylesheet()) method. In my case I can't use this method, because the image is drawn during run time. After the Image was drawn, I create a newQLineEditand want the just drawn image as a background. But this seems not to work. Below is a simplified version of the code I use:[...] QLineEdit *linetext = new QLineEdit(button->getText().c_str(), parent); linetext->setFixedSize(button->getWidth(), button->getHeight()); linetext->move(button->getLeftPosition(), button->getTopPosition()); linetext->setFrame(false); Button::BITMAP_t bm = button->getLastImage(); QPixmap pix(bm.width, bm.height); QImage img(bm.buffer, bm.width, bm.height, QImage::Format_ARGB32); pix.convertFromImage(img); QPalette palette; palette.setBrush(QPalette::Base, QBrush(pix)); // palette.setBrush(QPalette::Window, QBrush(pix)); // <-- doesn't work either linetext->setPalette(palette); obj->object.linetext->show(); [...]Is there a way to get the image to the background of
QLineEdit? What is wrong with my code?
The above method work fine withQLabel.In case you're interested in the whole code (huge!) you can download the open source version with svn:
svn co https://www.theosys.at/svn/tpanelThe part in question is in file
tqtmain.cppstarting at line 1378 (methodMainWindow::inputText(Button::TButton* button)). The code compiles on Linux and for Android. You need, beside QT, the Skia library (https://skia.org/docs/user/download) to compile the code. -
Hi
I think it's maybe the picture itself as
QPalette palette; QPixmap pix(":/abstract-geometric-pattern-lines-rhombuses-260nw-573952828.jpg"); palette.setBrush(QPalette::Base, QBrush(pix)); ui->lineEdit_2->setPalette(palette);
just worked.
try save it to a file and see if its valid.