Create Hyperlink in TableView



  • 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 :) ?


  • Qt Champions 2016

    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.



  • 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.


  • Qt Champions 2016

    @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.



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



  • @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



  • @VRonin thks a lot !!!

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

    Without

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

    Is working pretty good.


Log in to reply
 

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