No icon with QStyleOptionButton
I have got a weird problem.
I need to have some buttons in my QTableView. I used to use QAbstractItemView::setIndexWidget() method, but it is not very responsible when working with larger models. Therefore I decided to switch to QStyledItemDelegate. My buttons have icons (and icons only, no text). When working with setIndexWidget, I used the following code:
Code:
ClientDetailsButton::ClientDetailsButton(const Client* _client,
__current(_client) {
setIcon
(QIcon(":/uiIcons/button-details.png"));
}
And it worked perfectly. But when I switch to delegate, I use it like that:
Code:
button.rect = _option.rect;
button.text.clear();
button.
icon = QIcon(":/uiIcons/button-details.png");
button.
state = _option.
state |
QStyle::State_Enabled;
if (_index == __button)
button.
state |
= QStyle::State_Sunken;
The button itself is fine, but its empty. There is no icon visible. Suprisingly, when I use, for example:
Code:
button.
icon = QIcon::fromTheme("dialog-information",
QIcon(":/uiIcons/button-details.png"));
the theme icon is visible. But if Qt cannot find the theme icon, the replacement is still blank. I tried everything I could think of and have no idea why it doesn't work. Anyone has any ideas?
Re: No icon with QStyleOptionButton
Maybe too late, but maybe interesting also for others...
You have to set the size of the image too.. (button.iconSize = QSize(32,32);)