Results 1 to 2 of 2

Thread: No icon with QStyleOptionButton

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2014
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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:
    Qt Code:
    1. ClientDetailsButton::ClientDetailsButton(const Client* _client,
    2. QWidget* _parent) :
    3. QPushButton("", _parent),
    4. __current(_client) {
    5.  
    6. setIcon(QIcon(":/uiIcons/button-details.png"));
    7. }
    To copy to clipboard, switch view to plain text mode 
    And it worked perfectly. But when I switch to delegate, I use it like that:
    Qt Code:
    1. button.rect = _option.rect;
    2. button.text.clear();
    3. button.icon = QIcon(":/uiIcons/button-details.png");
    4. button.state = _option.state | QStyle::State_Enabled;
    5.  
    6. if (_index == __button)
    7. button.state |= QStyle::State_Sunken;
    8.  
    9. QApplication::style()->drawControl(QStyle::CE_PushButton, &button, _painter);
    To copy to clipboard, switch view to plain text mode 
    The button itself is fine, but its empty. There is no icon visible. Suprisingly, when I use, for example:
    Qt Code:
    1. button.icon = QIcon::fromTheme("dialog-information", QIcon(":/uiIcons/button-details.png"));
    To copy to clipboard, switch view to plain text mode 
    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?

  2. #2
    Join Date
    Dec 2007
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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)

Similar Threads

  1. QTabWidget Place icon with no text and stretch icon over tab
    By alenn.masic in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2013, 12:25
  2. Replies: 7
    Last Post: 1st April 2013, 12:22
  3. Adding stylesheet and icon to QStyleOptionButton
    By riarioriu3 in forum Newbie
    Replies: 0
    Last Post: 8th August 2012, 14:12
  4. Creating a list with icon and text in the center of icon
    By prophet0 in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2011, 03:03
  5. Couple of questions: main window icon + toolbar icon
    By bpackard in forum Qt Programming
    Replies: 0
    Last Post: 20th March 2008, 19:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.