unable to click the hyperlink in textedit
hi ,
i want to get a url from the dialog box lik this
QString baseUrl= QInputDialog::getText(this, tr("URL"),tr("Link:"), QLineEdit::Normal, "", &ok);
after getting the url, i can only insert the url in the textedit, but it is not looking like a hyperlink.
How to make the link in a clickable format.??????
i have usd anchorclickd too
Re: unable to click the hyperlink in textedit
The easiest solution is to wrap your url into html link tag (<a>) and add that to the text edit (provided that it is in rich text mode).
Alternatively use QTextCursor::insertText() to insert your url with a proper text char format that contains the anchor.
Re: unable to click the hyperlink in textedit
wrap my url?
Lets say that i am getting url from the above code
QString baseUrl= QInputDialog::getText(this, tr("URL"),tr("Link:"), QLineEdit::Normal, "", &ok);
now i cant insert the baseUrl into the <a href .......> tag ???
Re: unable to click the hyperlink in textedit
Quote:
Originally Posted by
rleojoseph
now i cant insert the baseUrl into the <a href .......> tag ???
Why not?
Re: unable to click the hyperlink in textedit
ya. its working now. But i got a NEW problem now. after inserting the link in the TextEdit, the text which i am typing now is looking like a hyperlink. i have inserted a link lik www.google.com , whatever the text am typing after that it is like Hyperlink. even i tried a lot with Qtextcursor.
Re: unable to click the hyperlink in textedit
Hey what's up with you? Please do not start multiple threads about the same topic, and I told you days ago to use HTML...
And as to your new problem, you probably didn't close the a tag correct. Please show us the code.
Re: unable to click the hyperlink in textedit
Sorry for posting multiple threads
here is the code
Code:
bool ok;
if (ok && !baseUrl.isEmpty())
{
//int i=cursor.position();
//qDebug("%d",i);
cursor.insertHtml(link);
Whatever i am typing after inserting url , all the texts are becoming as hyperlink.
Re: unable to click the hyperlink in textedit
Make sure the cursor is positioned after the link is closed. For example insert a space after closing the "a" tag. For more advanced things you'll have to use the text document and text cursor api. Bottom line is you need to make sure the current text char format is not the one associated with the link. There are many one that are likely to make it work.
Re: link is not added with image.
Hi, So far i have used QImage, QTextCursor, QTextCharFormat to make the image as a link.
And i have used the QTextCharFormat::anchorRef also but when i am inserting the image using
format.setAnchorHref(QString("<a href=\"%1\"> %1 </a> ").arg(file)); , the image is only added not the url.
can any1 can fix this?
Added after 1 21 minutes:
cursor.insertImage will insert only the image, but i couldn't add the link to image.
:confused::confused::(
Re: link is not added with image.
setAnchorHref() should only contain the href, not any html tags.
I didn't test this but try adjusting something like this to your needs:
Code:
if(title.isEmpty()) title = url;
format.setAnchor(true);
format.setAnchorHref(url);
cursor.insertText(title, format);
cursor.setFormat(original);
return cursor;
}
addLink(te->textCursor(), "http://www.qtcentre.org", "QtCentre");
For adding an image instead of text you will probably want to use QTextCursor::insertImage() instead of insertText():
Code:
format.setAnchor(true);
format.setAnchorHref(url);
format.setName(imageName);
cursor.insertImage(format);
Re: TextBrowser in TextEdit.
Oh man, still the same problem, so stick with this thread!
QTextBrowser inherits QTextEdit, not the other way around. If you what to know how the textbrowser can emit a signal like anchorClicked() have a look at the sources and find it out. Qt is open source! I haven't done it, but I guess they are reimplementing mousePressEvent(), check the current cursor at the position the event occur, and look if it is a link. if so, the signal is emitted.
Re: TextBrowser in TextEdit.
No sir. I have already done the clicking the URL in TextBrowser widget. But now am trying to implement it in the TextEdit Widget. ok?
The problem is the signals available in the TextEdit are
copyAvailable,currentCharFormatChanged,cursorPosit ionChanged (),redoAvailable,selectionChanged ,textChanged (),undoAvailable.
So whenever i click the URL in the TextEdit which Signal is emitted?? that is what i was asking.
Re: TextBrowser in TextEdit.
Quote:
Originally Posted by
rleojoseph
No sir. I have already done the clicking the URL in TextBrowser widget. But now am trying to implement it in the TextEdit Widget. ok?
The title says: "unable to click the hyperlink in textedit". I mixed that up in the first place too.
Quote:
The problem is the signals available in the TextEdit are
copyAvailable,currentCharFormatChanged,cursorPosit ionChanged (),redoAvailable,selectionChanged ,textChanged (),undoAvailable.
So whenever i click the URL in the TextEdit which Signal is emitted?? that is what i was asking.
And the answer has given in my last post: the text edit has no such signal. You have to do it yourself.
Re: TextBrowser in TextEdit.
Hi.. This is wat i finally found out. This might be useful for others. The URL can be inserted into a TextEdit but those links cannot be clicked, if u want click events go for TextBrowser.
If you want the click event in the TextEdit, Creating Custom Signals and Slots might be the possible Solution.....:)