Nominate our 2022 Qt Champions!

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());

  • Thanks for this. It was really helpful.

    I couldn't get it to work with your syntax for connecting the signal and slot but the code below worked for me. Not sure if something has changed over the years - I am v new to Qt.

    connect(contentWidget, SIGNAL(clicked(QModelIndex)), this, SLOT(testSlot()));
    void HelpWindow::testSlot()
        QModelIndex testIndex = mpHelpEngine->contentWidget()->currentIndex();
        QHelpContentItem *item = mpHelpEngine->contentModel()->contentItemAt(testIndex);
        QUrl testUrl = item->url();

    Of course the testSlot function needs to be added to the Slots in the .h file.

    Hope this helps someone out there

Log in to reply