No icon with QStyleOptionButton

I have a strange problem.

I need to have some buttons in my QTableView. I used the QAbstractItemView :: setIndexWidget () method, but it is not very responsible for working with larger models. So I decided to switch to QStyledItemDelegate. My buttons have icons (and only icons, no text). When working with setIndexWidget, I used the following code:

ClientDetailsButton::ClientDetailsButton(const Client* _client,
                                         QWidget* _parent) :
    QPushButton("", _parent),
    __current(_client) {

  setIcon(QIcon(":/uiIcons/button-details.png"));
}

And it worked perfectly. But when I switch to delegation, I use it like this:

QStyleOptionButton button;
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;

QApplication::style()->drawControl(QStyle::CE_PushButton, &button, _painter);

The button itself is fine, but its empty. There is no icon. Amazing when I use, for example:

button.icon = QIcon::fromTheme("dialog-information", QIcon(":/uiIcons/button-details.png"));

The theme icon is displayed. But if Qt cannot find the theme icon, the replacement remains empty. I tried everything I could think of, and I have no idea why this is not working. Does anyone have any ideas?

+4
1

, b utton.iconsize=QSize(16,16). - (-1,-1), . !

+5

Source: https://habr.com/ru/post/1529669/


All Articles