pyQt5: setting font & size in Qtextbrower - pyqt5

I have been using Qt designer to develop a GUI. So far so good except for setting the font and size for Qtextbrowser object.
I redirect print outputs (mainly tables & numbers) toward this textbrowser. It doesn't look like so nice to read s I want to change the font in fixed width but I have been unsuccesful so far.
I tried to change the font and size in Qt Designer --> No changes.
Code looks like this:
font = QtGui.QFont()
print(font)
font.setFamily("Courier")
font.setPointSize(10)
self.textBrowser.setFont(font)
self.textBrowser.setObjectName("textBrowser")
Thanks for any help.
S/

Related

VB.NET Charting Series Format A Name options

I would like to know if it's possible to format a "Data - Name" of The Series such as; Font, Size Alignment, and positioning.
I run into an issue where Printing the chart doesn't display the name(different than images) because of its length.
However, App and controls do, correctly. So I was hoping to re-format when calling on Print.
There is no code(mine) as I couldn't find anything related to what I am trying to achieve it seems like all refers to an actual data points formatting but NOT a name formatting itself.
Thank you

How to make long text fit into a text_frame? Python-pptx

I'm working with python-ppt to create a portfolio of candidates in a Powerpoint presentation. There is one candidate per slide and each of them has provided information about themselves like name, contacts and a minibio (the problem I'm here to solve)
The text_frame, created with values of height and width, must fit the slide but must a contain all lenght of minibios, which is not happening.
In a long phase (>200 char, with font size 12) it exceeds the size of the text box and get "out" of the slide, so, in presentation mode or a PDF file, the "overrun" of text is lost
Is there any way to confine the text to the shape/size of the text_frame? (extra help if the solution wont change font size)
Just found one parameter that helped to find the answer
When creating a text_box object with slides.shapes.add_textbox() and adding a text_frame to it, the text_frame.word_wrap = True limits the text to be contained inside the dimentions of the text_box
The code shows it better
# creates text box with add_textbox(left, top, width, height)
txBox = slide.shapes.add_textbox(Cm(16),Cm(5),Cm(17),Cm(13))
tf = txBox.text_frame
tf.word_wrap = True
Before word_wrap parameter
After word_wrap parameter
The short answer is "No". PowerPoint is a page-layout environment, and much like the front page of a newspaper, text "story" content needs to be trimmed to fit the allotted space.
We're perhaps not used to this because word-processing, spreadsheet, and web-page content is "flowed" into a (practically) unlimited space, but the area of a PowerPoint slide is quite finite. Also, using it for large text blocks is somewhat of an off-label use. There is a certain amount of flexibility provided by reducing the font size, but not as much as one might expect. Even accommodating 20% additional text requires what appears as a pretty radical change in font size.
I've encountered this problem again and again, and the only solution I have ever seen work reliably is hand-curating the content to fit.
python-pptx has one experimental feature to address this but its operation has never been very satisfactory and it's tricky to get working. https://python-pptx.readthedocs.io/en/latest/api/text.html#pptx.text.text.TextFrame.fit_text
The business of fitting text is the role of a rendering engine, which python-pptx is not.

VBA in Word: CopyAsPicture method ignores text size as well as some font faces

The CopyAsPicture method in VBA in Word (I am using Word 2010 and 2016) is to transform a given piece of text (some string selected in the document) into a picture.
Microsoft provides this sample script in its tutorials:
Sub CopyPasteAsPicture()
'Origin: https://learn.microsoft.com/en-us/office/vba/api/word.selection.copyaspicture
ActiveDocument.Content.Select
With Selection
.CopyAsPicture
.Collapse Direction:=wdCollapseEnd
.PasteSpecial DataType:=wdPasteMetafilePicture
End With
End Sub
For testing the CopyAsPicture method I used however the following script which I found in a related question in this forum:
Sub CopySelPasteAsPicture()
' Take a picture of a selection and paste it at the document end
' Source: https://stackoverflow.com/questions/8888145/convert-text-to-image-in-microsoft-word
With Selection
.CopyAsPicture
End With
ActiveDocument.Content.Select
With Selection
.Collapse Direction:=wdCollapseEnd
.TypeParagraph
.TypeParagraph
.PasteSpecial DataType:=wdPasteMetafilePicture
End With
End Sub
I tested this but I find two problems with it:
1) Text size is ignored. Text sized, say, 28 pt will be rendered in the resulting picture as 12 pt or something like that
2) Not all font faces get recognized. I have some special fonts (both in otf and ttf) that I want to picturize that way. These fonts are ignored, and instead I get a picture of a standard font (Times New Roman or whatever).
I do not find help for these issues in Microsoft's VBA documentation.
Additional information:
1) Why do I want to do this? I use some rare fonts that people do not have usually, and including them into the .docx also does not work reliably. I have to share these documents with colleagues, and they should be able to see also the characters from the special fonts.
2) Picture generation works with cyrillic characters in standard fonts. That's good so far.
3) Picture generation also works with fonts that have cliparts instead of pictures (such special fonts are used e.g. for childrens books or textbooks for people to train reading and writing)
4) The font that in my case does not get picturized (but replaced by pictures of some standard system font) is a font I got as .otf, but I transformed it to .ttf (because I thought I could then include into the documents, but this did not work either). - I did so far not test if it would work with the original otf, but I doubt it because there was so far no problem with ttf versus otf fonts.
Question:
I would like to understand why font size and some font faces are ignored.
Of course, ideas how to solve this are also welcome.
.PasteSpecial DataType:=wdPasteMetafilePicture
A metafile picture is meant to retain font data. So when the document is opened on a device that doesn't have that font Word will follow its font substitution rules. I also vaguely recall that there is a font related bug in the metafile format.
I suggest that you play with the other paste data types and see what works best for you.

VBA to change Visio font style by font name instead of font index?

I'm hoping to use VBA to change the font style of the texts in shapes(from Calibri to Verdana). Currently I have (a snippet of the code)
Visio.ActivePage.Shapes(1).Characters.CharProps(visCharacterFont) = 235#
235 is the font index for Verdana in my system. However, the font index is very unstable and can change on different computers. Is there a way to change the font style by font name instead, e.g. ...="Verdana"? It's possible in excel, but I couldn't find similar syntax in Visio. Thanks in advance!
You can check what is ID for Verdana font on current PC
Dim Verdana_ID As Integer
Verdana_ID = ActiveDocument.Fonts.Item("Verdana").ID
And after this step set this ID as character's font
Visio.ActivePage.Shapes(1).Characters.CharProps(visCharacterFont) = Verdana_ID

Set PPT Font to 'Body' Type

I am not able to paste the entirety of my code, but the crux is that I have a textbox in PPT 2013, myTb, that I have (programmatically) pasted some text into. I now want to perform the following two actions:
See if the original text was the PPT 'body default' font (e.g. 'Calibri (body)' vs. 'Calibri' in the MS Ribbon)
If it was the body default, set the new text to also be the body default.
I can't seem to figure either part out, even though I have experimented with reading/writing from/to most of the Shape.TextFrame[n].TextRange.Font.Name... fields. I also had two confounding points to ask about, regarding the Shape.TextFrame.TextRange.Font.NameComplexScript field:
This field does not seem to be a 'complete' indicator of body-default vs non-body-default font. The reason is that if this textbox is originally the body-default ('Calibri (body)'), it will read '+mn-cs', but then I can change the font to the non-default variant ('Calibri'), and it still reads '+mn-cs'.
I then proceed to change the textbox to an entirely different font, which changes this field to the font's name as expected. However, if I then change back to the body-default font (or any other font, for that matter), this field remains on the previous font's name.
To set the font to the body or heading font, you need to use a weird bit of syntax:
{object}.Font.Name = "+" + FontType + "-" + FontLang
Where:
FontType is "mj" or "mn" for Major (headings) or Minor (body) respectively.
FontLang is "lt", "cs" or "ea" for Latin, Complex Scripts or East Asian
For example to set the font to the theme's body text font for Latin text:
ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Font.Name = "+mn-lt"
A bit late to the party, but I found this in case anyone needs it.
Edit: This is C# code, using the Interop PowerPoint namespace.
string headingsThemeFont = Globals.ThisAddIn.Application.ActivePresentation.SlideMaster.Theme.ThemeFontScheme.MajorFont.Item(MsoFontLanguageIndex.msoThemeLatin).Name;
string bodyThemeFont = Globals.ThisAddIn.Application.ActivePresentation.SlideMaster.Theme.ThemeFontScheme.MinorFont.Item(MsoFontLanguageIndex.msoThemeLatin).Name;