| Qtqlineedit input box Input Panel keyboard eventfilter change window position it |
|
1. Define an Event Filter
Bool mydialog: eventfilter (qobject * o, qevent * E ){ If (e-> type () = qevent: mousebuttonpress) & (O = lineedit )) { Updataposition (); // display the Input Panel at the bottom of the input box. Inputpanel. Show (); Return true; } Else returnqdialog: eventfilter (o, e );} 2. Install the Event Filter on the input box, lineedit-> installeventfilter (this); void mydialog: updateposition (){ Qwidget * widget = focuswidget (); // obtain the control of the current focus If (! Widget) Return; Qrectwidgetrect = widget-> rect (); // obtain the control's geometric information, that is, width and height. Qpointpanelpos = qpoint (widgetrect. Left (), widgetrect. Bottom (); // coordinates of the lower left corner of the space and the upper left corner of the space Panelpos = widget-> maptoglobal (panelpos); // convert to global, that is, coordinates starting from the upper left corner of the screen Input. Move (panelpos); // move the upper left corner of the Input Panel to the coordinates.}