QTextBrowser trouble with css - c++

In my application im trying to load a simple formatted text with some images into QTextBrowser. When im trying to set my image size using :
<img style="width: 128px; height: 128px;" src=":/new/prefix1/Star-five.png"/>
The qtextbrowser is automatically modifying my html and removing "style". Is there something i do wrong? Im setting this style from form editor.

Question asnwered. Need to use width height properties without "px".

Related

Open html file on button click with python-plotly

Im writing a python script which reads from a file and plots graphs in seperate html files with plotly.I would like to have a button to redirect from one page to another(load from disc).I've come across this :
updatemenus = list([
dict(type="buttons",
buttons=list([dict(label = 'Next',method = 'update', args = ['shapes', []])])
)])
layout=go.Layout(title="Iteration_Number:"+str(counter_iter),updatemenus=updatemenus)
But this is used for updating data or changing layout. What i want is open another html page from disc on button click. Is that possible ?
I have also seen this :
import webbrowser
url = "file:///home/tinyOS/Simulation_"+str(counter_iter+1)+".html"
webbrowser.open(url)
Which helps me open a new page but again i want it to happen when clicking on the button.Any ideas? Thanks a lot !
From the question I understand that you want a group of buttons on the plotly graph, that are going to open a plotly graph in new tab.
So you need not use plotly buttons for this requirements.because they are mainly used for restyle, relayout, etc., so there is no relation between these buttons and opening links in new tabs.
I would recommend having simple html buttons which on click are going to take you to the new tab.
A simple way to do it will be, wrap the plot in a div set to relative positioning and make the div wrapping the button absolute positioned and position it anywhere over the graph, please refer the below example and let me know if this solves your issue!
Solution:
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.offline as py_offline
from IPython.core.display import display, HTML
py_offline.init_notebook_mode()
display(HTML("""
<style>
.wrapper{
position:relative;
}
.button-group{
position:absolute;
top:40px;
left:90%;
z-index: 30000;
}
.button-group a{
display:block;
}
</style>
"""))
What is happening in the above piece of code is, first we include the necessary packages, then styles needed!
data = [go.Bar(
x=['giraffes', 'orangutans', 'monkeys'],
y=[20, 14, 23]
)]
display(HTML("""
<div class="wrapper">
<div class="button-group">
Google It
Yahoo It
</div>"""
+str(py_offline.plot(data, filename='plot_name' ,output_type="div", include_plotlyjs=False))
+ '</div>'))
The main piece of code, with which we embed the buttons is shown above, first we define the plotly plot , then using display and html functions, we can embed the buttons inside a div with class button-group and with CSS we position that button.
Please do try the above code and let me know if there are any doubts regarding the working!

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>

HTML inserted into QTextEdit does not conform to style sheet

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

How do I display a large image when rolling over a thumbnail that allows text to be written over the large image

I have images in a table and want to click on each and have them enlarged on the screen. I can find alot of these snippets online but none I have found allow for writing text over the enlarged images. These pix are artwork and need a copywrite statement on top of them when enlarged. Anyone know either how to do this or where to find it online....thx....David
The only way I can find to add text over an image is to create the image as the background. Setting up a division and table allowed me to only have the background apply to a certain area of the screen.
You can try this code :
<div id="lare_img">
<div class="copyright">Your copy right text here </div><div class="img_file"><img src="img_01.jpg"></div></div>
and style CSS :
<style>
#lare_img{
width:100% // change to your image large width ;
height:100% // change to your image large height;
position:absolute;
}
.copyright{
position:absolute;
bottom:20px;
left:20px;
z-index:999;
}
.img_file{
width:100%;
height:100%;
float:left;
}
</style>

How to create a bold, red text label in Qt?

I want to write a single, bold red line in my application using Qt.
As far as I understand, I would create a QLabel, set its textFormat to rich text and give it a rich text string to display:
QLabel *warning = new QLabel;
warning->setTextFormat(Qt::RichText);
warning->setText("{\\rtf1\\ansi\\ansicpg1252 {\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;} {\\colortbl;\\red255\\green0\\blue0;} \\f0 \\cf0 this is bold red text}");
I tested this rich text string in a rich text editor and it displays fine.
But Qt displays the whole string with all braces, keywords and backslashes instead of "this is bold red text". What am I doing wrong?
Thank you for your help.
Try using HTML formatting: <b><font... etc </b>.
Qt Designer does it like this: <span style=" font-size:8pt; font-weight:600; color:#aa0000;">TextLabel</span>
You can use Qt StyleSheets and set the styleSheet property of QLabel
warning->setStyleSheet("font-weight: bold; color: red");
Qt supports most CSS styles on its QWidget-derived classes. You don't need to set the text format to Qt::RichText for this to work.
Qt uses a simple HTML subset for formatting.
You can also do it programmatically using the settext function. Something like this:
QString labelText = "<P><b><i><font color='#ff0000' font_size=4>";
labelText .append("Text what u want to display");
labelText .append("</font></i></b></P></br>");
QLabel label->setText(labelText);
You can do it in a single line as well.