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
Forum Updated to NodeBB v4.3 + New Features

Create Hyperlink in TableView

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.3k Views 2 Watching
  • 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.
  • G Offline
    G Offline
    G4bandit
    wrote on 11 Dec 2017, 18:20 last edited by G4bandit 12 Nov 2017, 18:23
    #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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 11 Dec 2017, 18:53 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
      • G Offline
        G Offline
        G4bandit
        wrote on 11 Dec 2017, 21:02 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.

        M 1 Reply Last reply 11 Dec 2017, 21:06
        0
        • G G4bandit
          11 Dec 2017, 21:02

          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.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 11 Dec 2017, 21:06 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
          • G Offline
            G Offline
            G4bandit
            wrote on 14 Dec 2017, 11:03 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));

            V 1 Reply Last reply 14 Dec 2017, 11:07
            3
            • G G4bandit
              14 Dec 2017, 11:03

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

              V Offline
              V Offline
              VRonin
              wrote on 14 Dec 2017, 11:07 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
              • G Offline
                G Offline
                G4bandit
                wrote on 14 Dec 2017, 12:13 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

                1/7

                11 Dec 2017, 18:20

                • Login

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