Results 1 to 5 of 5

Thread: Can't change toolbutton icon

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Can't change toolbutton icon

    I have a toolbutton created in Designer with an action actionEdits.
    Made it a toggle button with a little code. Would like to change the icon when it toggles. The icon from Designer comes up fine when the application starts, but when you click the icon, it disappears as the code tries to change it.

    The icon files are both in a directory <application-root>/images and listed in the qrc with all my other icons. Yes, I did run qmake after adding them.
    And
    Qt Code:
    1. QDirIterator it(":", QDirIterator::Subdirectories);
    2. while (it.hasNext())
    3. qDebug() << it.next();
    To copy to clipboard, switch view to plain text mode 
    Shows they are there.
    Here is the code for changing the icon on toggle, but it is obviously not working since the icon disappears on the first click.
    Qt Code:
    1. ui->actionEdits->setIcon(QIcon("./images/application_edit.png"));
    To copy to clipboard, switch view to plain text mode 
    So what could be wrong here?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Can't change toolbutton icon

    Quote Originally Posted by waynew View Post
    Here is the code for changing the icon on toggle, but it is obviously not working since the icon disappears on the first click.
    Qt Code:
    1. ui->actionEdits->setIcon(QIcon("./images/application_edit.png"));
    To copy to clipboard, switch view to plain text mode 
    So what could be wrong here?
    Can that image be found?

  3. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't change toolbutton icon

    Yes, I can view the icon images in the images directory with a graphics program, and this code:
    Qt Code:
    1. QDirIterator it(":", QDirIterator::Subdirectories);
    2. while (it.hasNext())
    3. qDebug() << it.next();
    To copy to clipboard, switch view to plain text mode 

    Yields this:
    ":/images"
    ":/images/application_edit.png"
    ":/images/undo.png"
    ":/images/new.png"
    ":/images/info.png"
    ":/images/page_red.png"
    ":/images/copy.png"
    ":/images/close.png"
    ":/images/open.png"
    ":/images/message.png"
    ":/images/viewdetailed-32.png"
    ":/images/save.png"
    ":/images/paste.png"
    ":/images/cut.png"
    ":/images/quit.png"
    ":/images/standardbutton-save-32.png"
    ":/images/1uparrow.png"
    ":/images/consoleButtonGlyph.png"
    ":/images/1downarrow.png"

  4. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't change toolbutton icon

    Update: if I put in an absolute path, it works. But why not relative?

  5. #5
    Join Date
    Dec 2010
    Posts
    13
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't change toolbutton icon

    Thanx for this thread.

Similar Threads

  1. How to change my Application icon and Text
    By damodharan in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2010, 16:49
  2. Change button Icon on toggle
    By bizmopeen in forum Qt Programming
    Replies: 3
    Last Post: 13th July 2009, 23:17
  3. How to change Icon size in QMenu?
    By alex chpenst in forum Qt Programming
    Replies: 4
    Last Post: 3rd September 2008, 14:16
  4. Change Application Icon
    By cutie.monkey in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2008, 07:14
  5. Icon Change in Drag & Drop
    By joseph in forum Qt Programming
    Replies: 1
    Last Post: 9th December 2006, 12:03

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.