PDA

View Full Version : Displaying Icon



Seema Rao
9th February 2006, 09:55
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

Everall
9th February 2006, 10:28
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

zlatko
9th February 2006, 11:11
QToolButton::setUsesBigPixmap ( bool enable )

maiby will help:o

Seema Rao
9th February 2006, 13:50
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?

Everall
9th February 2006, 21:43
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