Results 1 to 5 of 5

Thread: Displaying Icon

  1. #1
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Displaying Icon

    Hi all,

    I have a problem, I am trying to display Icon on a Tool button. Icon size should cover
    the tool button fully, but it covers partially. Here is the code I have written, I have
    used setIconSize() to set the size,

    #include <QtGui>
    #include <QToolButton>
    int main( int argc, char **argv )
    {
    QApplication a( argc, argv );
    QWidget *mywidget= new QWidget;
    QToolButton *button = new QToolButton (mywidget);
    button->setIcon(QPixmap("Door.bmp"));
    button->setIconSize(QSize(button->width(), button->height()));
    mywidget->show();
    return a.exec();
    }

    Thanks in advance,
    Seema Rao

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Displaying Icon

    what does
    qDebug() <<"width = " <<mywidget->width();
    give as a result ?

    My guess is that your mywidget is not in a layout or dialog, so it doesn't have a width, by consequence button->width() hasn't one either.

    Cheers

  3. #3
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Displaying Icon

    Qt Code:
    1. QToolButton::setUsesBigPixmap ( bool enable )
    To copy to clipboard, switch view to plain text mode 
    maiby will help

  4. #4
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Arrow Re: Displaying Icon

    Even if I add tool button to a layout, BMP file doesnt
    mapped fully to tool button size. Please some body
    explain how to do it?

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Displaying Icon

    qDebug() << "button->width()" << button->width(); //gives 100
    qDebug() << "button->height()" << button->height(); //gives 30

    So the Toolbuton is initialized with a width and height you don't want I suppose.

    you could look at it in another way :

    get the height and width of the pixmap, and use them to get the aspect ratio.
    Set the height of your button at a value you like, and use the ratio to calculate the width.
    then use this height and width in button->setIconSize(QSize(w, h)); as you did.
    Now your button will follow the ratio of your pixmap.

    Hope this helps

Similar Threads

  1. QMessageBox missing icon
    By zanth in forum Qt Programming
    Replies: 3
    Last Post: 8th July 2010, 21:20
  2. Displaying icon in tableView
    By JPNaude in forum Qt Programming
    Replies: 3
    Last Post: 14th October 2008, 07:28
  3. Couple of questions: main window icon + toolbar icon
    By bpackard in forum Qt Programming
    Replies: 0
    Last Post: 20th March 2008, 19:03
  4. Mac application and the Dock Icon
    By sekelsenmat in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2007, 10:23
  5. QSystemTrayIcon doesn't show icon ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 25th January 2007, 19:17

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.