Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting QHelpContentWidget QUrl with Single-Click
QtWS25 Last Chance

Getting QHelpContentWidget QUrl with Single-Click

Scheduled Pinned Locked Moved General and Desktop
qhelp
4 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    polluxpolaris
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      polluxpolaris
      wrote on last edited by polluxpolaris
      #2

      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;
      }

      1 Reply Last reply
      0
      • P Offline
        P Offline
        polluxpolaris
        wrote on last edited by
        #3

        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;
        
        }
        
        1 Reply Last reply
        0
        • A Offline
          A Offline
          AhmedAlshawi
          wrote on last edited by
          #4

          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();
              ui->textBrowser->setSource(testUrl);
              return;
          }
          

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

          Hope this helps someone out there

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved