Show html tags in tableview
May i know how can i display html tags in a tableview.
I have an entry in my database <a href="goo">hello</a>.. When i get values from the database and put it in my tableview. The cell must have the value "hello" as an hyperlink.
Can any one please help me.
Let the cell contain a [[doc:QLabel]] and use your html code ( <a >) in the label.
But in the cell the data is displayed as <a >hello</a>. But i wanted it to display only "hello".
May i know this.
Edit: sorry forget this. I misunderstood it...
QTableView has no possibility to display richtext by default.
You will have to implement a QItemDelegate and return a QLabel as editor widget. Then you have to turn the cell in "edit mode":openPersistentEditor ( const QModelIndex & index ) where you want to show the link.
check out the "star delegate exmaple":http://qt-project.org/doc/qt-4.8/itemviews-stardelegate.html for reference.
Thanks. It worked. The link is shown.
As a link if i specify the path to a file.That is Suppose i wanted to open a local file in an editor , instead of opening a site in web browser. May i know how can i do this.
I have an .cpp file in my local directory. I wanted to open it in an editor when i click on the link.
I have given the following.
but it doesnt work .it opens some site on my webbrowser.
Should i change the reference link given in the database.As of now it is like the following
QLabel::setOpenExternalLinks() takes a bool as parameter and tells QLabel to open hyperlinks using QDesktopServices::openUrl() ... not the way you are doing it
since your url starts with ":" and not with "file:///" the OS tries to open it in the web browser. Use "QUrl::fromLocalFile()":http://qt-project.org/doc/qt-4.8/qurl.html#fromLocalFile
QUrl::fromLocalFile("C:/file.txt"); //returns QUrl("file:///C:/file.txt")
May i know in database what ref should i give?
Currently it is.
Now the link have given is
Still it is trying to open in the browser and say file not found. I wanted to open the file in text editor or some editors. May i know this?
i don't get it... Why do you use setOpenExternalLinks() this way? As i said it takes a bool parameter.
Thus QLabel will do the work with QDesktopServices::openUrl() for you already.
What is the following output:
qDebug() << QUrl::fromLocalFile(”/fullpathtothefile/Plus1.txt”);
This should work ... only as long as the file exists:
Thank You. It works now.
My doubt is then what is the use of setOpenExternalLinks(). Will that be implicitly called by QDesktopServices::openUrl(QUrl("file:///fullpathtothefile/Plus1.txt")).
[quote author="deepakkakkeel" date="1369288923"]
My doubt is then what is the use of setOpenExternalLinks(). Will that be implicitly called by QDesktopServices::openUrl(QUrl("file:///fullpathtothefile/Plus1.txt")).[/quote]
You are kidding right?! You must be because i already posted it twice in this thread what setOpenExternalLinks() does and how to use it!
Sorry actually i was not able to understand the concept thoroughly.