Problems when adding a combo box to a toolbar and KActionCollection in KF6
Stefano Crocco
stefano.crocco at alice.it
Mon Oct 30 08:09:38 GMT 2023
On lunedì 30 ottobre 2023 01:07:43 CET Albert Astals Cid wrote:
> 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
>
Yes, it's in the kf6 branch of the Konqueror repository. Note that the code is
actually split into several functions in src/konqmainwindow.cpp which are
called by the main window constructor:
- the combo box is created in the function initCombo (line 2832) called from
line 278 of the constructor
- the actions are created in the function initActions (line 3322) called from
line 279 of the constructor
- the combo box is given the toolbar as a parent and displayed in lines
287-288 of the constructor.
Stefano
More information about the kde-devel
mailing list