Want to do the following effect: When the mouse to move to the button, the button becomes larger, the icon for a large, the mouse is not on the button when the button becomes small, the icon is small, the feeling is more cool
Implementation principle: Set the listening properties for each button
void Mainhomeform::init () { //For button registration event Ui->systemsetbutton->installeventfilter (this); Ui->zonesetbutton->installeventfilter (this);}
System Listener Listener Button object bool Mainhomeform::eventfilter (Qobject *target, qevent *e) {if (target = = Ui->systemsetbutton) { if (e->type () = = Qevent::enter) {ui->systemsetbutton->resize (163,91); Qicon *mouseonicon = new Qicon (":/new/prefix1/back/system set 2.png"); Ui->systemsetbutton->seticon (*mouseonicon); } else if (e->type () = = Qevent::leave) {ui->systemsetbutton->resize (115,60); Qicon *mouseofficon = new Qicon (":/new/prefix1/back/system settings. png"); Ui->systemsetbutton->seticon (*mouseofficon); }} else if (target = = Ui->zonesetbutton) {if (e->type () = = Qevent::enter) {Ui-> ; Zonesetbutton->resize (163,91); Qicon *mouseonicon = new Qicon (":/new/prefix1/back/Area Control 2.png"); Ui->zonesetbutton->seticon (*mouseonicon); } else if (e->type () = = Qevent::leave) {Ui->zonesetButton->resize (115,60); Qicon *mouseofficon = new Qicon (":/new/prefix1/back/Zone control. png"); Ui->zonesetbutton->seticon (*mouseofficon); } }}
OK, first the binding button of the Installeventfilter is the current form, in the form of the EventFilter event, see which button moved to the top, you can.
Another is that when the mouse is pressed down, move to the top of the button will change:
Track mouse movement events when the mouse moves to the middle button, change the icon size and content void Mainhomeform::mousemoveevent (Qmouseevent *e) { e->accept (); if (Enterbtn (E->pos (), Ui->systemsetbutton)) { ui->systemsetbutton->setsizeincrement (163,91) ; Qicon *mouseonicon = new Qicon (":/new/prefix1/back/system set 2.png"); Ui->systemsetbutton->seticon (*mouseonicon); }} Write your own function to determine if the mouse is within a button area bool Mainhomeform::enterbtn (Qpoint pp, Qtoolbutton *btn) { int height = btn->height (); int width = btn->width (); Qpoint Btnminpos = Btn->pos (); Qpoint Btnmaxpos = Btn->pos (); Btnmaxpos.setx (Btn->pos (). x () +width); Btnmaxpos.sety (Btn->pos (). Y () +height); if (pp.x () >= btnminpos.x () && pp.y () >= btnminpos.y () && pp.x () <= btnmaxpos.x () & & Pp.y () <= btnmaxpos.y ()) return true; else return false;}