[Qt-interest] Determining Whether Focus is in the Combobox DropDown

Jake Colman colman at ppllc.com
Wed Oct 6 16:04:55 CEST 2010


I am porting an application from Qt3 to Qt4.  I have an event filter
that traps FocusOut events for a specific widget.  That event filter
needs to know whether the FocusOut event have moved focus into the
combobox's dropdown menu.  

In Qt3 I can do the following:

 if( Event->type() == QEvent::FocusOut )
 {
   QWidget* EditorWidget = cellWidget( currentRow(), currentColumn() );
   if( EditorWidget && EditorWidget == Obj )
   {
     QWidget* FocusWidget = qApp->focusWidget();
     // If the FocusWidget is NULL, then focus is on a non-Qt widget and we
     // should endEdit.  Otherwise, we endEdit only if the FocusWidget is
     // not a child of the EditorWidget (which would make it a pop-up menu)
     // and not the combox drop-down list box.
     if( !FocusWidget ||
         QString(FocusWidget->name()) != static_cast<const char*>("in-combo") )
     {
       endEdit( currentRow(), currentColumn(), true, false );
       return true;
     }
   }
 }

The above code relies on the fact that when the combobox dropdown is
opened, focus is on a widget named "in-combo".  If we are not focused on
the "in-combo" widget, then we endEdit().

Since the combobox has been dramatically rewritten for Qt4, this code
does not work - even when using the Q3ComboBox since it is just a
wrapper around the revised underlying implementation.

Does anyone have any suggestions on how I can port this code?

TIA!

...Jake


-- 
Jake Colman | Director, Software Development
Principia Partners LLC
101 West Elm Street | Conshohocken | PA 19428 | +1 (610) 755 9770
t: +1 (610) 755 9786 | c: +1 (610) 348 2788 | f: +1 (201) 221 8929
e: colman at ppllc.com | w: www.principiapartners.com
Credit technology innovation awards winner 2008 and 2009




More information about the Qt-interest-old mailing list