HTML inserted into QTextEdit does not conform to style sheet - c++

I have a docked QTextEdit which I am using to emulate a debug terminal in a QT c++ gui, and have it set to a black background with white text.
I am trying to use it to print out error messages from QXmlSchemaValidator, but the messages from the schema validator are in html format, and whenever I insert them into the QTextEdit, it reverts to it's default font, and I end up with black text on a black background.
The actual message is something like:
<html xmlns='http://www.w3.org/1999/xhtml/'>
<body>
<p>Content of element
<span class='XQuery-keyword'>minValue</span> does not match its type definition: <span class='XQuery-data'>fu</span> is not valid according to <span class='XQuery-type'>xs:decimal</span>..
</p>
</body>
</html>
using setAcceptRichText(false) doesn't solve the problem, and if I use insertPlainText() to add text to the lineEdit, it removes all the line breaks and leaves the html tags in the error message, which is unacceptable.
Is there some way I can display the HTML rich text, but without blowing away my style sheet font?

I tested it on my computer. It works perfectly. Use this:
edit->setHtml(htmlDescription);
edit->selectAll();
edit->setTextColor(Qt::green);
//Ok, but clear selection
QTextCursor cur = edit->textCursor();
cur.clearSelection();
edit->setTextCursor(cur);

It's sort of a kludge, but the workaround that I went with was to remove the HTML tags from the schema validator message before adding it to the text edit.
QString errorMsg = msg.statusMessage().remove(QRegExp("<[^>]*>"));
textEdit->setText(errorMsg);

Related

django's urlize changing text color of entire string containing url substring

I am loading a long text from a database into a Django template. This string contains a url https://yyyyyy as part of the text. I use django's urlize in order to display the url as actual links, however adding urlize is causing the entire text including the link to change color to blue. Removing the urlize leaves the text as black. I only want the text to be black. How can I stop this color from changing to blue while using urlize?
Here is my implementation :
<p style="font-size: 15px; color: black" class="tm-pt-30">
{{ value.description | safe | urlize }}
</p>
The class tm-pt-30 is only responsible for padding.
#raphael was right. My problem is I had wrapped the entire card containing the code in the question with <a></a> in order to make the whole card clickable. The fix for this was only wrapping the appropriate elements.

OrchardCMS Replacement Tokens for Query Results displaying HTML tags instead rendering them

I am having problems understanding the token system for the output of query / projections.
If I leave the property as is it displays the text content with HTML formatting intact.
But I need to wrap it with a tag, the html tags get displayed as text.
Rewrite Results -> Rewrite output
<div class="collapse" id="toggle_{Content.Id}">
{Content.Fields.CaseStudy.ClientChallenge} </div>
I am trying to create a collapsible text area, I already have a button that hides/unhides the content.
Why is it displaying as text instead of rendering the tags properly.
I think this is because I don't know how replacement tokens work.
Another example problem is up one level on the edit Layout, I want to set the item class to work-item {Category}, Category being the name/title of a property, which I am using for grouping.
Right above the projection: I want to include some html that lists all the Categorys in a ul i.e. data-filter=".experiential" I have tried things like: work-item {Category} and work-item {Content.Fields.CaseStudy.Category}. Category is a "term" (?) from a taxonomy.
I feel like I am failing to understand how it all works.
Submitted as a bug https://github.com/OrchardCMS/Orchard/issues/7355
Will edit and post if it is fixed. In case anoyong else comes across this issue.

Sitecore - setting background-image a div to a CMS value

I've been try to add the background image of a div to a value from Sitecore (8.0) in C# MVC using the code
<div style="background-image: url({Model.MyImage.Src})>
Where MyImage is of type Image as returned by GlassView
This is returning html such as
<div style="background-image: url(/~/media/myFolders/myImage.ashx)">
This image isnt being displayed when the page is rendered- although the url resolves when entered into the browser's address bar so it must be an issue with the .ashx extension as a background image for a div.
I also tried using Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem) but this also returned me the ashx which couldn't be resolved!
Try background-image: url('#Model.Image.Src'). While your example doesn't show it, you most likely have spaces in your folder or file name, which requires single or double quotes.
Add single quotes around it.
url('{Model.MyImage.Src}')
Should make this
url('/~/media/myFolders/myImage.ashx')
for my case sitecore 8.2 stop working below code because of style attribute
I have replaced style attribute with img tag and start working
<span><img src="#item.GetImageUrl("MyImage")" alt="" class="icon" /></span>

Sitecore page editor render as HTML

I have a Sitecore item ("Content Item"), which has a rich text as "<h2>Header text</h2>".
I want this to be rendered as html.
But using a field renderer when I try
FieldRenderer1.Item = DatabaseManager.MasterDatabase.GetItem(//content item);
FieldRenderer1.FieldName = "Content";"
Text is rendered as "<h2>Header text</h2>" in the mark up. How do I get them render as HTML?
After reading the comments, I think may be trying this might work.
<sc:FieldRenderer id="HeaderText" runat="server" FieldName="HeaderText" />
This fixed my issues when I was trying something similar at my end.
FieldName specification is a must when it comes to FieldRenderers.

Add custom HTML class property to selected block in a QTextEdit

I am not new to Qt, but I can't find how to add a custom css class to the selected block in a QTextEdit.
As far as I know,format is changed whit code like this:
QTextCursor cursor = textEdit->textCursor();
QTextBlockFormat bfmt;
// Apply format changes
cursor.setBlockFormat(bfmt);
When I do this, the generated HTML code creates a span with inlined style in it, but what I want is to insert the css class:
<SPAN class='myclass'>text</span>
I am missing a function inside QTextBlockFormat to set the css class of the text.
You should be able to emulate this behavior by manually adding <span style=""> tags to your selected text:
QString oldText = cursor.selectedText();
// not the best way to concat three strings, but for example only...
cursor.insertHtml(QString("<span class=\"%1\">%2</span>").arg("myclass").arg(oldText));
selectedText() will return currently selected text, and insertHtml() will insert new text at the beggining of the cursor, deleting current selection, if any.