Frage

I am using Qt5 and having some problems in setting the back ground image of a QPushButton. I am using Qt Creator and Design to drag and drop the QPushButton. After that I created a source folder and placed an image in that directory and I googled and tried doing

ui->pushButton_play->setStyleSheet(QString::fromUtf8("background-image: url(:/source/play.png);"));

but no success...am I creating the folder in a wrong place?..I created in D:\Qt5_PROJECT_NAME\source or will I make the url(:\\source\\play.png). Nothing is working...please help...

War es hilfreich?

Lösung

Did you add the images file into .qrc file? A URL start with : has indicated that It will be searched in .qrc file. If .qrc file didn't used, URL should not start with :. Maybe you should access the image file as

ui->pushButton_play->setStyleSheet(QString::fromUtf8("background-image: url(source/play.png);"));

This is The Qt Resource System documentation.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top