[SOLVED] get Style from QPushButton



  • Hiho everybody,
    is there a way to get the current Stylesheet from a QPushButton?

    What I want to do is to tell a QPushButton to take the style from another QPushButton.

    The problem is that I have to generate the Backgroundimage dynamically with QPainter like this:

    @
    QPixmap* pixmap = new QPixmap("../media/interface/stats/sammler.gif");
    QPainter paint(pixmap);
    paint.drawPixmap(0,0, sammler_armL_green);
    paint.drawPixmap(0,0, sammler_armR_green...
    QIcon icon(*pixmap);
    QSize iconSize(pixmap->width(), pixmap->height());
    pushbutton1->setIconSize(iconSize);
    pushButton1->setIcon(icon);
    @

    so I cant use normal stylesheets and save them.

    Here is a short description of what I want to acchieve:
    There are 24 Buttons for 24 units of a strategygame which show the state of the selected units (if they are injured or something else)
    And if I deselect a Unit the button which represents this unit, now represents the next one, and so on, and the last button gets hidden.

    I dont want to do all the math and regenerate the picture for each button everytime I deselect a unit, so it would be usefull to tell the first button to take the image from the second, the second from the third and so on.

    Btw, I tryed to declare the QPixmap variable outside the changeButtons() function.
    If this would work I could take one QPixmap for every button and tell the first button to use the QPixmap of the second and so on.
    I dont know why but if I declare it outside the function and set the image within, than the image isn't displayed.

    What can I do to solve this problem?

    Thanks in advance and best regards

    Ritschratsch



  • bq. is there a way to get the current Stylesheet from a QPushButton?

    QWidget::stylesheet()



  • Hi Chris,
    first of all thank you for your answer :)

    The problem is that I generate the image for the button with QPainter, so if I call button->stylesheet() the function will return an empty qstring because ther isn't really a stylesheet.

    But I solved the problem by making a QIcon for every button, so I'm able to tell the button to use the next QIcon in the QIcon array :)

    Best regards
    Ritschratsch


Log in to reply
 

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