Important: Please read the Qt Code of Conduct -

Getting QHelpContentWidget QUrl with Single-Click

  • The linkActivated() signal of QHelpContentWidget only triggers on a double-click but I want to trigger on a single-click.

    I am able to successfully trigger a slot on clicked() and selectionChanged(int index) but I don't know how to get the QUrl from the QHelpContentWidget with the index.

    I also tried helpEngine->contentWidget()->setEditTriggers(QAbstractItemView::CurrentChanged); without success.

    Does anyone know how to get a QUrl from QHelpContentWidget using an int index?

  • I learned 2 things:

    1. I need to access the QUrl directly from QHelpEngine, not its QHelpContentWidget.
    2. I cannot access QHelpEngine content using a int index, I must use a QModelIndex.

    Here's my current solution:


    void MainWindow::testSlot(){
    QModelIndex testIndex = helpEngine->contentWidget()->currentIndex();
    QHelpContentItem *item = helpEngine->contentModel()->contentItemAt(testIndex);
    QUrl testUrl = item->url();

  • Here's a better way that passes the clicked index instead of checking for the currently selected index:

    void HelpMenu::onContentClick(QModelIndex testIndex){
        QVariant v = helpEngine->indexModel()->data(testIndex, Qt::DisplayRole);
        QMap<QString,QUrl> item = helpEngine->indexModel()->linksForKeyword(v.toString());

Log in to reply