Search code examples
c++cssqtuser-interfaceqtgui

Image on a button not working properly in QT


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");
}


Solution

  • 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.