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. Create Hyperlink in TableView
QtWS25 Last Chance

Create Hyperlink in TableView

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.2k 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.
  • G4banditG Offline
    G4banditG Offline
    G4bandit
    wrote on last edited by G4bandit
    #1

    I am using SSMS database and have paths given like C:/....
    I would like to do this data from database clickable, means it shall workl like a hyperlink. I prefer not to change the data in this way:
    <a href= C:/... >Click</a>
    I tried that but it did not helped to me because the C:/.. was not cliclable
    I guess I miss something like
    ui->QLabelName->setOpenExternalLinks(true);

    Or does any one have a faster idea?
    I would be very thankfull for every opions.

    Other point:regarding Forum at all
    For me the search is not that comfortable. I would prefer to have at least the catagory "Database/SQL". Does someone know to whom I can transfer my christmas wishes :) ?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      What are the path actual pointing to ?
      What should happen when you click on them?
      Is it file ?

      When you say in TableView
      you mean inside one cell?
      like one link pr cell ?

      You could use
      clicked(const QModelIndex &)
      for the cell and then simply do what you want when clicked.

      1 Reply Last reply
      0
      • G4banditG Offline
        G4banditG Offline
        G4bandit
        wrote on last edited by
        #3

        There are links to different folders e. g. NetWorkDrives.
        I will try as soon as possibles but I need to say to the tableview somtehing like "allow links" I mean globally for one columb.

        mrjjM 1 Reply Last reply
        0
        • G4banditG G4bandit

          There are links to different folders e. g. NetWorkDrives.
          I will try as soon as possibles but I need to say to the tableview somtehing like "allow links" I mean globally for one columb.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @G4bandit
          Hi
          Tableview knows no concept of links.
          To make it open say explorer you will have to program it when cell is clicked.
          Check the QModelIndex to see if right coloum and then You can use
          QDesktopServices::openUrl()
          to open the folder/drive.

          1 Reply Last reply
          3
          • G4banditG Offline
            G4banditG Offline
            G4bandit
            wrote on last edited by VRonin
            #5

            @mrjj Thks a lot!!!

            • I have generated a slot from "TableView" so when clicked. QModelIndex is given as param in the new generated function
            • extracted the content of a cell like this
            QString strPath = model->record(index.row()).value("Name of the Column").toString();
            
            • And very important, - I had to fight a bit with this part, replace the \ with /
            strPath.replace("\\","/");
            - And the final
            

            QDesktopServices::openUrl(QUrl(strPath));

            VRoninV 1 Reply Last reply
            3
            • G4banditG G4bandit

              @mrjj Thks a lot!!!

              • I have generated a slot from "TableView" so when clicked. QModelIndex is given as param in the new generated function
              • extracted the content of a cell like this
              QString strPath = model->record(index.row()).value("Name of the Column").toString();
              
              • And very important, - I had to fight a bit with this part, replace the \ with /
              strPath.replace("\\","/");
              - And the final
              

              QDesktopServices::openUrl(QUrl(strPath));

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @G4bandit said in Create Hyperlink in TableView:

              And very important, - I had to fight a bit with this part, replace the \ with /

              I found that QUrl::fromUserInput is a friend in cases like these

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              3
              • G4banditG Offline
                G4banditG Offline
                G4bandit
                wrote on last edited by
                #7

                @VRonin thks a lot !!!

                QDesktopServices::openUrl(QUrl::fromUserInput(strPath));
                

                Without

                strPath.replace("\\","/");
                

                Is working pretty good.

                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