簡體   English   中英

pyqt中QTextEdit中的文本格式

[英]text formatting in QTextEdit in pyqt

我是PyQt編程的新手,我已經使用PyQt4設計器開發了一個GUI,該GUI看起來像圖中的一個: 在此處輸入圖片說明

當我單擊check_inertia按鈕時,QTextEdit小部件將填充圖片中顯示的文本。 如我們所見,文本看起來很亂,我需要控制QTextEdit的格式。

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
*  ---------------------------------------------------------------------

因此,如何才能將上述正確的格式獲取到GUI的QTextEdit中。 我應該使用什么? 樣式表? 幫我這個

請使用monospace字體或consola字體,或者在控制台或編程中使用其他字體。 您可以在樣式表中進行設置;

QTextEdit {
    font: 10pt "Consolas";
}

放入您的QTextEdit ;

yourQTextEdit.setStyleSheet ('''
    QTextEdit {
        font: 10pt "Consolas";
    }
''')

注意: QPlainTextEdit也可以使用它,我建議僅用於顯示原始文本並實現相同的QTextEdit

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM