Unsolved How to use function actualSize() from QIcon?
-
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?
-
@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 -
@jsulm This function return current icon size. Ok. And why I have to add size, which I would like?
-
@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
-
@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.
-
@TomNow99 You can use huge size as parameter, like QSize(10000, 10000)
-
@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?
-
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.
-
@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.
-
Strange requirement... and not that easy to accomplish. You first need access to the view and then calc where the icons are. Happy coding :)
-
@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 ):
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?
-
@TomNow99
Hi
How do you get the icon painted there ? -
@mrjj I don't paint icon here. I just setIcon in QStandardItem and I change position to right using delegate
-
@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 ?
-
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.
-
@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.
-
@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. -
This post is deleted! -
@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?
-
@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)