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. How to use function actualSize() from QIcon?
Forum Updated to NodeBB v4.3 + New Features

How to use function actualSize() from QIcon?

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 4 Posters 3.4k 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.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by
    #1

    Hi,

    I would like to get size of icon in my QComboBox item and I think I have to use function actualSize(), but I don't how.

    (const QSize &size, QIcon::Mode mode = Normal, QIcon::State state = Off)

    What is size param?

    jsulmJ 1 Reply Last reply
    0
    • T TomNow99

      Hi,

      I would like to get size of icon in my QComboBox item and I think I have to use function actualSize(), but I don't how.

      (const QSize &size, QIcon::Mode mode = Normal, QIcon::State state = Off)

      What is size param?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @TomNow99 said in How to use function actualSize() from QIcon?:

      What is size param?

      The size you want to have
      https://doc.qt.io/qt-5/qicon.html#actualSize

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by
        #3

        @jsulm This function return current icon size. Ok. And why I have to add size, which I would like?

        jsulmJ 1 Reply Last reply
        0
        • T TomNow99

          @jsulm This function return current icon size. Ok. And why I have to add size, which I would like?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @TomNow99 said in How to use function actualSize() from QIcon?:

          And why I have to add size, which I would like?

          Because you want to have the icon in a specific size? An icon can contain several versions of the icon each in a different size. If you want to know which sizes are available use https://doc.qt.io/qt-5/qicon.html#availableSizes

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • T Offline
            T Offline
            TomNow99
            wrote on last edited by
            #5

            @jsulm So when I have icon in item in QCombBox, what I have to add as size? I would like only get the size of icon in this item.

            jsulmJ 1 Reply Last reply
            0
            • T TomNow99

              @jsulm So when I have icon in item in QCombBox, what I have to add as size? I would like only get the size of icon in this item.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @TomNow99 You can use huge size as parameter, like QSize(10000, 10000)

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TomNow99
                wrote on last edited by
                #7

                @jsulm When I do that I get original size of my image. When I add it to comboBox, my image is smaller. So I can use this function to get that smaller size?

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Why do you need this icon size at all? QComboBox has a function iconSize() but even this can be wrong when a stylesheet is set.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TomNow99
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher I have items with icons in QComboBox. I would like to know when I click on icon, so I would like to have a position on this icons.

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Strange requirement... and not that easy to accomplish. You first need access to the view and then calc where the icons are. Happy coding :)

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      1
                      • T Offline
                        T Offline
                        TomNow99
                        wrote on last edited by TomNow99
                        #11

                        @Christian-Ehrlicher I think I have a good height, but I have problem with a width. I would like to know how many pixels is between end of icon and end of item comboBox ( look at the picture - this place is where is the yellow arrow ):

                        combo.png

                        When I change width of comboBox this size is the same, so I try find this value here:

                        https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qcombobox.cpp.html

                        but I can't. I look at good place?

                        mrjjM 1 Reply Last reply
                        0
                        • T TomNow99

                          @Christian-Ehrlicher I think I have a good height, but I have problem with a width. I would like to know how many pixels is between end of icon and end of item comboBox ( look at the picture - this place is where is the yellow arrow ):

                          combo.png

                          When I change width of comboBox this size is the same, so I try find this value here:

                          https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qcombobox.cpp.html

                          but I can't. I look at good place?

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @TomNow99
                          Hi
                          How do you get the icon painted there ?

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            TomNow99
                            wrote on last edited by
                            #13

                            @mrjj I don't paint icon here. I just setIcon in QStandardItem and I change position to right using delegate

                            mrjjM 1 Reply Last reply
                            0
                            • T TomNow99

                              @mrjj I don't paint icon here. I just setIcon in QStandardItem and I change position to right using delegate

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @TomNow99
                              Ok, so its just a RightAlign so delegate dont know more about where it is ?

                              But if you dont use StyleSheets, is the size not correct (actualSize) when/after you create the icon ?

                              1 Reply Last reply
                              0
                              • Christian EhrlicherC Offline
                                Christian EhrlicherC Offline
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                The position depends on the style, as I already said it's a nice task without a real advantage. I would simply use the n right pixels as area of interest.

                                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                Visit the Qt Academy at https://academy.qt.io/catalog

                                1 Reply Last reply
                                1
                                • T Offline
                                  T Offline
                                  TomNow99
                                  wrote on last edited by
                                  #16

                                  @mrjj I use this code to move icon to right:

                                  class StyledItemDelegate: public QStyledItemDelegate{
                                  public:
                                     using QStyledItemDelegate::QStyledItemDelegate;
                                  protected:
                                      void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const{
                                          QStyledItemDelegate::initStyleOption(option, index);
                                          option->decorationPosition = QStyleOptionViewItem::Right;
                                      } 
                                  };
                                  

                                  I don't use StyleSheets. I don't use actualSize(). I use iconSize() from QComboBox.

                                  mrjjM 1 Reply Last reply
                                  0
                                  • T TomNow99

                                    @mrjj I use this code to move icon to right:

                                    class StyledItemDelegate: public QStyledItemDelegate{
                                    public:
                                       using QStyledItemDelegate::QStyledItemDelegate;
                                    protected:
                                        void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const{
                                            QStyledItemDelegate::initStyleOption(option, index);
                                            option->decorationPosition = QStyleOptionViewItem::Right;
                                        } 
                                    };
                                    

                                    I don't use StyleSheets. I don't use actualSize(). I use iconSize() from QComboBox.

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @TomNow99
                                    Hi
                                    I can't find anything in QStyle that would give the actual Rect so I agree with
                                    Mr Ehrlicher that it would be far easier to assume the icon is as width as its height even it's not pixel
                                    accurate.

                                    1 Reply Last reply
                                    0
                                    • T Offline
                                      T Offline
                                      TomNow99
                                      wrote on last edited by
                                      #18
                                      This post is deleted!
                                      1 Reply Last reply
                                      0
                                      • T Offline
                                        T Offline
                                        TomNow99
                                        wrote on last edited by TomNow99
                                        #19

                                        @mrjj Is it possible to get QPixmap from item in QComboBox? I try using grab in combo->view(), but when I would like to do it my combo must be shown ( I would like to hide this combo ).

                                        So my question is: can I grab / render QWidget when it is hidden?

                                        mrjjM 1 Reply Last reply
                                        0
                                        • T TomNow99

                                          @mrjj Is it possible to get QPixmap from item in QComboBox? I try using grab in combo->view(), but when I would like to do it my combo must be shown ( I would like to hide this combo ).

                                          So my question is: can I grab / render QWidget when it is hidden?

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

                                          @TomNow99
                                          Hi
                                          yes, you can call render to have it draw itself to say a pixmap.
                                          https://doc.qt.io/qt-5/qwidget.html#render-1
                                          (for a full widget)

                                          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