Problems when adding a combo box to a toolbar and KActionCollection in KF6

Albert Astals Cid aacid at kde.org
Mon Oct 30 00:07:43 GMT 2023


El diumenge, 29 d’octubre de 2023, a les 18:38:50 (CET), Stefano Crocco va 
escriure:
> Hello to everyone,
> while porting Konqueror to KF6, I've hit a problem I don't know how to
> solve. The issue is that it's impossible to give focus to the location bar
> by clicking on it with the mouse as you can do in KF5.
> 
> After spending some hours trying to find out the cause of this, I reached
> the conclusion that it has something to do with the main window's
> actionCollection. A shortened version of the code which creates the location
> bar is the following:
> 
> KonqMainWindow::KonqMainWindow() : KParts::MainWindow()
> {
>   //...
>   m_combo = new KonqCombo(nullptr) //KonqCombo derives from KHistoryComboBox
> //...
>   QWidgetAction *comboAction = new QWidgetAction(this);
>   actionCollection()->addAction(QStringLiteral("toolbar_url_combo"),
> comboAction);
>  comboAction->setDefaultWidget(m_combo);
>   //...
>   setXMLFile(QStringLiteral("konqueror.rc"));
>   createGUI(nullptr);
> 
> //"locationToolBar" is the name of the toolbar where the widget should be
> //inserted
>   m_combo->setParent(toolBar(QStringLiteral("locationToolBar")));
>   m_combo->show();
>  //...
> }
> 
> If I remove the addAction method, the location bar is, of course, displayed
> floating above the toolbar and it can be given focus clicking on it with the
> mouse. The same happens if I remove the setDefaultWidget line. I tried
> adding the action to the toolbar using
> 
> QAction *a = toolBar(QStringLiteral("locationToolBar"))->addWidget(m_combo);
> actionCollection()->addAction(QStringLiteral("toolbar_url_combo"), a);
> 
> This gives the same problem as the previous code; however, if I remove the
> second line, the focus works correctly again. This is what made me suppose
> the problem is related to KActionCollection.
> 
> Initially, I thought that the problem was caused by some event filter or
> event handler, so I tried creating a different action with new QComboBox,
> new action name and so on, but the results were the same. Also, using a
> QLineEdit instead of a QComboBox changed nothing.
> 
> I tried looking at the source code of KActionCollection, but I couldn't find
> any significant difference between the KF5 and the KF6 version. The same
> can be said for Konqueror source code, however.
> 
> Can someone give me some hints about what's happening?

Is this code live in some branch so we can try it?

Cheers,
  Albert

> 
> Thanks in advance
> 
> Stefano






More information about the kde-devel mailing list