Originally Posted by
Snick
dice->setIcon(icona);
dice
->setIconSize
(QSize(103,
43));
dice->setGeometry(50, 50, 103, 43);
QToolButton* dice= new QToolButton(this);
QIcon icon;
icon.addPixmap(QPixmap("img/gioca_on.png"),QIcon::Active);
icon.addPixmap(QPixmap("img/gioca_off.png"),QIcon::Normal);
dice->setIcon(icona);
dice->setIconSize(QSize(103, 43));
dice->setGeometry(50, 50, 103, 43);
To copy to clipboard, switch view to plain text mode
Well, assuming "icona" in line 5 is a typo for "icon" (the compiler would catch it anyway), I had some success, using QIcon::addFile() rather than QIcon::addPixmap(). It needs an additional size parameter. The file parameter can be a regular file or a resource. Something like this:
QSize size
(MY_BUTTONW, MY_BUTTONH
);
pButton->resize(size);
pButton->setIconSize(size);
icon.
addFile(strIconNormalFName, size,
QIcon::Normal);
icon.
addFile(strIconActiveFName, size,
QIcon::Active);
pButton->setIcon(icon);
pButton->show();
QPushButton * pButton;
QIcon icon;
QSize size(MY_BUTTONW, MY_BUTTONH);
pButton = new QPushButton("", parent);
pButton->resize(size);
pButton->setIconSize(size);
icon.addFile(strIconNormalFName, size, QIcon::Normal);
icon.addFile(strIconActiveFName, size, QIcon::Active);
pButton->setIcon(icon);
pButton->show();
To copy to clipboard, switch view to plain text mode
I assume it should also apply to QToolButton but I didn't check. However, I run into a problem anyway: if the button has the focus, it is shown with the active image regardless of the mouse position.
On the same topic, what about if i want to use alpha-png (so with transparence) and don't want to show the normal PushButton Gui under the transparence?
This seems contradictory: if you do not want the graphics underneath to show through, do not use transparence. Or am I missing something?
Ciao,
M.
Bookmarks