PDA

View Full Version : Loading disabled icons



user_mail07
12th June 2007, 03:14
I am having trouble while loading disable icon to the application. I want to load two separate icons for instance when the push button is enabled I want to keep same icon that I am loading from UI file (coz it is already embedded in ui file ) but when that push button is disabled I want to load separate icon from some source. I want my icons to switch when the push button is enabled or disabled.

For instance :-


If((False = exitWindow)!!(test_mode =! CurrrenyMode))

{

if(pWarningButton)

{
pWarningButton->setEnabled(false);
//
QString str;
pWarningButton->setIconSet(QPixmap(“…1.png”);
}
}


else
{
pWarningButton->setEnabled(true);


}


//pWarningButton is simple push button that I am loading directly from UI file.
Such as:

pWarningButton = (QPushButton*)LoadWindow(mainWindowDlg,strWarning) ;
if(pWarningButton)
{
pWarningButton ->setEnabled(false);

connect(pWarningButton,SIGNAL(clicked()), this, SLOT(Slot1()));
}


The problem with above code is I got the icon that I have passed as parameter 1.png when button was disabled . But when button is enabled it never switches back to original icon of UI file.

IS there any way to switch icons according to enable/disable states? Or Do i have to define each time the source of bitmap when button is enabled or disabled.

wysota
12th June 2007, 09:57
You can add a second pixmap to the icon set so that Qt will swap icons on its own. Just take a look at QIconSet::setPixmap() and use the mode QIconSet::Disabled.

user_mail07
12th June 2007, 18:44
Thanks a lot that worked.


I have another similar question if i need to define different large icon sizes for toolbar and smaller icon size for menubar.

if (mToolbar)
{

mAction->setIconSet(QPixmap("largeICon" ),QIconset::Large))
}

if

if (mMenu)
{

mAction->setIconSet(QPixmap("smallIcon" ),QIconset::small))
}

When executes above code it just load only one size icon it overwrites another icon size.

wysota
12th June 2007, 21:19
Don't change the icon set. Add a pixmap with a different mode to the existing icon set.