Setting a backgroung image for a QPushButton does not work
-
Hi everyone,
I'm trying to set a background image for a QPushButton. I want the image to cover the entire button, I do not want to set it as the button's icon. I tried:
ui->pushButton->setStyleSheet("QPushButton { border-image:url(:/startProcessingButton) stretch;}");
ui->pushButton->setFlat(true);
ui->pushButton->setAutoFillBackground(true);I read about using border-image instead of background-image everywhere on the forum, but it doesn't seem to do the trick for me. It just displays a very tiny image in the center of the button that refuses to stretch to the size of the button. I also tried setting border-image-width and border-image-height, but that didn't take any effect.
I am new to Qt, so I would really appreciate your help.
-
Hi everyone,
I'm trying to set a background image for a QPushButton. I want the image to cover the entire button, I do not want to set it as the button's icon. I tried:
ui->pushButton->setStyleSheet("QPushButton { border-image:url(:/startProcessingButton) stretch;}");
ui->pushButton->setFlat(true);
ui->pushButton->setAutoFillBackground(true);I read about using border-image instead of background-image everywhere on the forum, but it doesn't seem to do the trick for me. It just displays a very tiny image in the center of the button that refuses to stretch to the size of the button. I also tried setting border-image-width and border-image-height, but that didn't take any effect.
I am new to Qt, so I would really appreciate your help.
@queenofdenile said in Setting a backgroung image for a QPushButton does not work:
url(:/startProcessingButton)
An image without an extension?
-
@queenofdenile said in Setting a backgroung image for a QPushButton does not work:
url(:/startProcessingButton)
An image without an extension?
@Christian-Ehrlicher, thank you for your answer. The image is added to my resources folder, and that is just an alias. It is correct, because I used the same model for example to add my background image.
-
Hi everyone,
I'm trying to set a background image for a QPushButton. I want the image to cover the entire button, I do not want to set it as the button's icon. I tried:
ui->pushButton->setStyleSheet("QPushButton { border-image:url(:/startProcessingButton) stretch;}");
ui->pushButton->setFlat(true);
ui->pushButton->setAutoFillBackground(true);I read about using border-image instead of background-image everywhere on the forum, but it doesn't seem to do the trick for me. It just displays a very tiny image in the center of the button that refuses to stretch to the size of the button. I also tried setting border-image-width and border-image-height, but that didn't take any effect.
I am new to Qt, so I would really appreciate your help.
-
@JoeCFD thank you very much for your answer.
I think it does find the path to the image, because it displays it in the middle of the button, only it's not the size I want (the white background is the background of my actual button, and the blue thing in the middle is my image):
-
@JoeCFD thank you very much for your answer.
I think it does find the path to the image, because it displays it in the middle of the button, only it's not the size I want (the white background is the background of my actual button, and the blue thing in the middle is my image):
@queenofdenile Mine works. Can you try to set the size of the button first and then style sheet? That is what I did.
-
@queenofdenile Mine works. Can you try to set the size of the button first and then style sheet? That is what I did.
@JoeCFD I tried to set the button size first and I am still getting the same behavior. I was wondering if you could share your code, I am sure I'm missing something obvious. Many thanks!