-1

I believe that I am doing something very wrong with my image buttons. I want to do something as simple as making them change its image whenever I hover over the button or by pressing it. Stylesheets are a bit ambiguous at the moment for me.

Here is a code snip where I think I am doing wrong with it:

border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;

hover:{border-image: url(:/Data/buttonNUC_Hover.png) 0 0 0 0 stretch stretch;};

pressed: {border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;};

Does anyone has any idea on what I can do?


Another thing that I tried, but to no avail.

void MainWindow::on_nucButton_pressed()
{
    ui->nucButton->setStyleSheet("QLineEdit {border-image: url(:/Data/buttonNUC_Pressed.png) 0 0 0 0 stretch stretch;}");
   // printf("Work?\n");
}

Joe Carr
  • 445
  • 1
  • 10
  • 23
  • Please add full code with HTML, CSS. – Hitesh Nov 15 '16 at 08:47
  • This is all I have within the stylesheet. No html was used, however, I can give you the xml bits? – Joe Carr Nov 15 '16 at 08:58
  • I tried something else. – Joe Carr Nov 15 '16 at 09:14
  • Reference: http://stackoverflow.com/questions/3137805/how-to-set-image-on-qpushbutton – ManuelH Nov 15 '16 at 12:20
  • Does not exactly help me as I tried doing it this way and I managed to get an image working on the button using stylesheets : border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch; And the others such as hover and pressed do not work which is absolutely bizarre as I had it working in a different project I did sometime ago. – Joe Carr Nov 15 '16 at 12:51

2 Answers2

0

Try this

ui->nucButton->setStyleSheet("QLineEdit {border-image: url(:/Data/buttonNUC_Pressed.png) 0 0 0 0 stretch stretch;}"
                             "QLineEdit:hover {border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;}"
                             "QLineEdit:pressed {border-image: url(:/Data/buttonNUC_Idle.png) 0 0 0 0 stretch stretch;}");
Andre
  • 186
  • 11
0

Solved it - just copy pasted the old project code into a new project and everything worked. For some reason my Qt project got bugged and it didn't let me do it.

Joe Carr
  • 445
  • 1
  • 10
  • 23