[英]text formatting in QTextEdit in pyqt
I'm new to PyQt programming and I've developed a GUI using PyQt4 designer and the GUI looks like the one in the picture: 我是PyQt编程的新手,我已经使用PyQt4设计器开发了一个GUI,该GUI看起来像图中的一个:
When I click the check_inertia button the QTextEdit widget gets populated with the text shown in the picture. 当我单击check_inertia按钮时,QTextEdit小部件将填充图片中显示的文本。 As we can see that the text appears to be messy, I need to control the formatting of the QTextEdit. 如我们所见,文本看起来很乱,我需要控制QTextEdit的格式。
The check_inertia button reads the contents of a .txt file and then prints the following information in the QTextEdit widget, the text file appears to be in this way of format: check_inertia按钮读取.txt文件的内容,然后在QTextEdit小部件中打印以下信息,该文本文件似乎采用这种格式:
* ============================== INERTIA ==============================
* File: /home/hamanda/Desktop/transfer/cradle_vs30_dkaplus01_fwd_dl140606_fem140704_v00.bif
* Solver: Nastran
* Date: 02/09/14
* Time: 08:35:30
* Text:
*
* Area +1.517220e+06
* Volume +5.852672e+06
*
* Structural mass +4.594348e-02
* MASS elements +0.000000e+00
* NSM on property entry +0.000000e+00
* NSM by parts (VMAGen and MPBalanc) +0.000000e+00
* NSM by NSMCreate +0.000000e+00
* Total mass +4.594348e-02
*
* Center of gravity
* in the global +1.538605e+02 +3.010898e+00 -2.524868e+02
* coordinate system
*
* Moments of inertia +8.346990e+03 +6.187810e-01 +1.653922e+03
* about the global +6.187810e-01 +5.476398e+03 +4.176218e+01
* coordinate system +1.653922e+03 +4.176218e+01 +7.746156e+03
*
* Steiner share +2.929294e+03 +4.016500e+03 +1.088039e+03
*
* Moments of inertia +5.417696e+03 +2.190247e+01 -1.308790e+02
* about the center +2.190247e+01 +1.459898e+03 +6.835397e+00
* of gravity -1.308790e+02 +6.835397e+00 +6.658117e+03
* ---------------------------------------------------------------------
So how can I get the exact formatting as seen above into the QTextEdit of the GUI. 因此,如何才能将上述正确的格式获取到GUI的QTextEdit中。 what should I use? 我应该使用什么? Stylesheets? 样式表? Help me with this 帮我这个
Please use font monospace
or consola
or other font is use in console or programming. 请使用monospace
字体或consola
字体,或者在控制台或编程中使用其他字体。 Your can set in style sheet; 您可以在样式表中进行设置;
QTextEdit {
font: 10pt "Consolas";
}
put in your QTextEdit
; 放入您的QTextEdit
;
yourQTextEdit.setStyleSheet ('''
QTextEdit {
font: 10pt "Consolas";
}
''')
Note : QPlainTextEdit
also can use this and I recommend use this for show raw text only and implement same QTextEdit
. 注意: QPlainTextEdit
也可以使用它,我建议仅用于显示原始文本并实现相同的QTextEdit
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.