Check for icon of QPushButton in if case



  • Hi,

    I have a QPushButton and I want to check if it has a certain Icon set and do stuff if it's the case. But I can't get the if statement working. I tried this
    @if(vlmPlayWidget_->playButton->icon() == QIcon(style()->standardIcon(QStyle::SP_MediaPlay))){
    //...
    }@

    but the compiler gives me error C2678. SO it seems like I'm using the wrong arguements for "==", but I don't understand why. Is there another way to get this working?

    thanks alot!


  • Lifetime Qt Champion

    Hi,

    You can't compare two QIcons like that.

    Why do you want to check the icon ?



  • Well, I'm trying to get my player work and I found some code on the internet, that seems to work. But he's comparing the text on the buttons, but I want to use Icons instead of text, so I'm trying to compare Icons. Maybe it also works to check for the player's current state, so I will try that. I wanted to stick to the example as close as possible to minimize mistakes from my side.

    I want to make my player work like a slideshow, because I'm not playing a movie, but I'm opening files with a certain time delay between and display the data. I thought I could get some Ideas from slideshow examples on how to handle play/pause/stop-buttons and player states. Right now I'm just running into infinite loops without a chance of canceling them :(. If by chance you know of any examples that might be helpful in my case, I'll be glad, if you share them with me :)


  • Moderators

    Sounds like a bad idea to me: A UI should reflect the state an application is in, it should not store that state.

    If something is playing is application state. There should be a way to retrieve that state from the object that does the playing, not from a button that happens to have a play icon on it! That is a maintenance nightmare: You would have to rewrite your application logic whenever somebody changes the UI. And UIs are the part that changes the most frequent.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.