I don't know why I'm having such a hard time finding this, but how do you add a hyperlink to QTextEdit or QTextBrowser? I'm trying to make something that has a list of links and when you click on a link you get the object that the link is referencing.
You need to set the acceptRichText property to true. Then you can just pass in HTML using the setHTML() slot.
win.setHTML("<a href="http://foo>Bar</a>");
Related
I have a QTableView with custom model and delegate. Task is to create cell which will contain image and hyperlink. By clicking on image user will copy hyperlink to clipboard, and by clicking of hyperlink user should open link in browser.
Is it a possible task?
Sure it is possible.
One of the way to solve this is to use call setIndexWidget() of view where you bypass QLabel with image or hyperlink or both using html (rtf).
Another way is to have own subclassed QItemDelegate in which you can reimplement createEditor() and set persistent editor with openPersistenEditor().
I want to do the next.
I have a program that must search and show some files. Before, I will do it with a QTextEdit, searching in the system and appending it when I found one.
Now I want to to the next: I want to show the name of the files but I want to select it in the GUI and, in anohter text edit, show the first line in the document.
So, I want to transform any file in something that I can select it (like a Radio Button, a check button or something like this).
I search info in the web but I dont found anything.
Anyone knows what I can do?
Usually you use something like a list view (list of selectable items) to do this. Fortunatley Qt has one! called QListView :)
See this link: QListView
You add one entry to the listview per file (for exampe). And then when you click/select an entry this triggers an event which you can make display the contents of the file in a nearby text box.
I'm trying to make an advanced find system. What i'm trying to do is to display in a QTextBrowser the line where the string that you're searching for and make it clickable. And for when you click it, it redirects you to that line.
How would this be possible?
You could simply use html anchor (<a href="...">) and connect to signal anchorClicked of QTextBrowser
I'm developing simple HTML editor and I like to be able to drag and drop from a button that for example represent HTML text line and in the Qwebkit the HTML text line will be created does Qt support such action?
How should I approach such thing?
I believe it does, yes.
What you need to do is set the mime type of your drag event. See here for details. Then on the webkit side, you can read the drops mime type to see what it was.
You can then try one of the following approaches:
Subclassing QWebView to implement dragEnterEvent and dropEvent. You can use event->pos() in the dropEvent to get the position where the drop occured.
Implementing the drop in javascript within your page, eg setting up an event listener for drops or however its done (I've never tried this).
I've got a QTableView for which I want to display the last column always in edit mode. (It's a QComboBox where the user should be able to always change the value.)
I think I've seen the solution in the Qt documentation, but I can't find it anymore. Is there a simple way of doing it?
I think I could archive this effect by using openPersistentEditor() for every cell, but I'm looking for a better way. (Like specifying it only one time for the whole column.)
One way to get the automatic editing behaviour is to call the view's setEditTriggers() function with the QAbstractItemView::AllEditTriggers value.
To display the contents of a given column in a certain way, take a look at QAbstractItemView::setItemDelegateForColumn(). This will let you specify a custom delegate just for those items that need it. However, it won't automatically create an editor widget for each of them (there could in principle be thousands of them), but you could use the delegate to render each item in a way that makes it look like an editor widget.
There are two possibilities:
Using setIndexWidget, but Trolltech writes:
This function should only be used to
display static content within the
visible area corresponding to an item
of data. If you want to display custom
dynamic content or implement a custom
editor widget, subclass QItemDelegate
instead.
(And it breaks the Model/View pattern…)
Or using a delegate's paint method. But here you have to implement everything like enabled/disabled elements yourself.
The QAbstractItemModel::flags virtual function is called to test if an item is editable (see Qt::ItemIsEditable). Take a look at Making the Model Editable in the Model/View Programming documentation.
I can't see an easy way to do this, but you might be able to manage by using a delegate. I honestly don't know exactly how it would work, but you should be able to get something working if you try hard enough. If you get a proper delegate, you should be able to set it on a whole view, one cell of a view, or just a column or row.