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:

    QObject::connect(helpEngine->contentWidget(),QHelpContentWidget::clicked,this,MainWindow::testSlot);

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



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

    QObject::connect(helpEngine->contentWidget(),QHelpIndexWidget::clicked,this,HelpMenu::onContentClick);
    
    void HelpMenu::onContentClick(QModelIndex testIndex){
    
        QVariant v = helpEngine->indexModel()->data(testIndex, Qt::DisplayRole);
        QMap<QString,QUrl> item = helpEngine->indexModel()->linksForKeyword(v.toString());
    
        textViewer->setSource(item.constBegin().value());
        return;
    
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.