PDA

View Full Version : Problem with qtoolbutton



moowy
22nd September 2006, 13:12
Hello I have a problem with QToolButton:
I want it to have different icons for different states (mouse_over,tab_focus,or none of that). I have implemented an eventFilter and it all works except I don't know how to implement the part where I leave a qtoolbutton with tab_focus, but the icon for that state still stays :( .
I want it to update itself so it would put the right icon.
here's the part of the code for the event filter :


if(button)
action = button->defaultAction();



if (event->type() == QEvent::KeyPress)
{
if(strcmp(objName,"LeftWidget")==0)
ctrl->setActionIcon(action,button->hasFocus() ? CPersonalControl::ImageType_Focus : CPersonalControl::ImageType_Normal);
rrr = true;

return QObject::eventFilter(obj, event);
}

else if (event->type() == QEvent::Enter)
{
//iz objekta dobim ven widget
if(strcmp(objName,"LeftWidget")==0)
{
ctrl->setActionIcon(action,button->hasFocus() ? CPersonalControl::ImageType_Focus : CPersonalControl::ImageType_MouseOver);
}

else
{
if(button)
{
if(action->data().canConvert(QVariant::Icon))
{
ikonca = action->icon();
QIcon ikona = action->data().value<QIcon>();
if(!(ikona.isNull()))
button->setIcon(ikona);
}
}
}

return QObject::eventFilter(obj, event);
}

else if (event->type() == QEvent::Leave)
{
// a widget in the toolbar was left
if(strcmp(objName,"LeftWidget")==0)
ctrl->setActionIcon(action,button->hasFocus() ? CPersonalControl::ImageType_Focus : CPersonalControl::ImageType_Normal);

else
{
if(button)
{
if(!(ikonca.isNull()))
button->setIcon(ikonca);

}
}

return QObject::eventFilter(obj, event);
}


else
{
// standard event processing
return QObject::eventFilter(obj, event);
}


I don't know if I should implement another QEvent or it's something completely else. Please help.

moowy
22nd September 2006, 13:30
I've solved it. I had to implement QEvent::FocusOut and QEvent::FocusIn events