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

Nicolas Fella nicolas.fella at gmx.de
Mon Oct 30 00:11:27 GMT 2023


On 10/29/23 18:38, Stefano Crocco wrote:
> 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?
>
> Thanks in advance
>
> Stefano

Hi,

focus and toolbar brings
https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/188 to my
mind. CanĀ  you check whether it works as you expect before that change?



More information about the kde-devel mailing list