How to use function actualSize() from QIcon?
-
@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 -
@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
-
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?
-
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.
-
@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)