Unsolved How to use function actualSize() from QIcon?
-
@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) -
@jsulm @mrjj @eyllanesc When I don't show popup I get very strange render.
combo->view()->render(&p); label->setPixmap(p); label->move(100,100);
EDIT:
Or other question:I can add QWidget using:
QModelIndex index = combo->model()->index(0,0); combo->view()->setIndexWidget(index, button);
And this add to my comboBox QPushButton. I set this button size to 10x10, so it is smaller than my comboBox popup. Now I would like to move this button, but when I moved it using button->move(50,20), it doesn't work. How can I do this?
EDIT2:
This second question is more important for me. I try using delegate, but with no good results.