Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] get Style from QPushButton
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] get Style from QPushButton

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ritschratsch
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

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

      QWidget::stylesheet()

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ritschratsch
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved