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. QIcon from standardpixmap
Forum Updated to NodeBB v4.3 + New Features

QIcon from standardpixmap

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 4.9k Views
  • 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.
  • QT-static-prgmQ Offline
    QT-static-prgmQ Offline
    QT-static-prgm
    wrote on last edited by
    #1

    Hi,

    i just wanted to add an icon to a pushbutton. For the icon i want to choose a standardpixmap. But i cannot find any conversion from qstyle:standardpixmap to icon.

    QIcon myIcon(QStyle::SP_TitleBarMinButton);

    does not work

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      http://doc.qt.io/qt-4.8/qstyle.html#standardIcon

      QIcon myIcon = QStyle::standardIcon(QStyle::SP_TitleBarMinButton);

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • QT-static-prgmQ Offline
        QT-static-prgmQ Offline
        QT-static-prgm
        wrote on last edited by
        #3

        does not work, because standardIcon is not a static member o.O
        But i cannot make an instance of it, because it's abstract.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          QIcon myIcon =QApplication::style()->standardIcon(QStyle::SP_TitleBarMinButton);

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2
          • QT-static-prgmQ Offline
            QT-static-prgmQ Offline
            QT-static-prgm
            wrote on last edited by
            #5

            that works now :D
            Do you know an easy way to make the icon white instead of black??

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6
              const auto avalSize = myIcon.availableSizes();
              QIcon invertedIcon;
              for(auto& singleSize : avalSize){
              QImage tempImage = myIcon.pixmap(singleSize).toImage();
              tempImage.invertPixels();
              invertedIcon.addPixmap(QPixmap::fromImage(std::move(tempImage)));
              }
              

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              4
              • QT-static-prgmQ Offline
                QT-static-prgmQ Offline
                QT-static-prgm
                wrote on last edited by
                #7

                The maximize icon worked fine, but the minimize is not very good. Any ideas what may happened here??

                1 Reply Last reply
                0
                • QT-static-prgmQ Offline
                  QT-static-prgmQ Offline
                  QT-static-prgm
                  wrote on last edited by
                  #8

                  @VRonin i need your help once more.

                  There are a few new findings. I need this splashscreen for a plugin that is compiled to .dll Because it's really much overhead to compile, deactivate the plugin, copy the dll, activate the plugin, test it, change code,... i copied a few parts to a test project. It's the same code, but different results.

                  Sourcecode for the whole plugin: https://git.rwth-aachen.de/carstenf/qtTsOverlay/tree/master
                  Test project: https://git.rwth-aachen.de/carstenf/testProject/tree/master

                  Plugin:
                  the minimize icon looks like on the picture above
                  the maximize icon works fine
                  when i select a item it is slightly highlighted white and the icon becomes a blue hue
                  when something is selected and i press the button or switch to an other window the text does not change, the highlight disappears, the icon is white again

                  Test application:
                  the minimize and maximize icon work both
                  when i select a item it gets a black dotted border and the icon becomes a blue hue
                  when something is selected and i press the button or switch to an other window the text become black, the dotted border disappears, the icon is still blue

                  Why is there this different behaviour and how can i fix it to this:
                  the minimize and maximize icon work both :P
                  when i select a item there is no highlight, no text an icon changes.
                  when something is selected and i press the button or switch to an other window nothing changes

                  1 Reply Last reply
                  0
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by VRonin
                    #9
                    QIcon invertedIcon;
                    for(auto singleMode : {QIcon::Normal,QIcon::Disabled,QIcon::Active,QIcon::Selected}){
                    for(auto singleState : {QIcon::On,QIcon::Off}){
                    const auto avalSize = myIcon.availableSizes(singleMode ,singleState );
                    for(auto& singleSize : avalSize){
                    QImage tempImage = myIcon.pixmap(singleSize,singleMode ,singleState).toImage();
                    tempImage.invertPixels();
                    invertedIcon.addPixmap(QPixmap::fromImage(std::move(tempImage)),singleMode,singleState);
                    }
                    }
                    }
                    

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    1 Reply Last reply
                    1
                    • QT-static-prgmQ Offline
                      QT-static-prgmQ Offline
                      QT-static-prgm
                      wrote on last edited by
                      #10

                      @VRonin still the same problem (updated the source on the repo.)

                      But the wrong icon the one thing, the other is that blue hue at the icons from the list entries

                      1 Reply Last reply
                      0
                      • VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by VRonin
                        #11

                        yes, this just inverts the colours of every icon. it will will just take a negative (like good old film cameras do), if you want to do something more refined, then that just replace tempImage.invertPixels(); with whatever pixel manipulation you want to apply. I also forgot the state and modein myIcon.pixmap above, fixed now

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        1 Reply Last reply
                        0
                        • QT-static-prgmQ Offline
                          QT-static-prgmQ Offline
                          QT-static-prgm
                          wrote on last edited by QT-static-prgm
                          #12

                          @VRonin invert is just fine. It works in the testsoftware. But in the final plugin (same code you can check it in the repositories i posted) it does not work

                          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