【问题标题】:text formatting in QTextEdit in pyqtpyqt中QTextEdit中的文本格式
【发布时间】:2014-11-01 08:20:38
【问题描述】:

我是 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 中。我应该用什么?样式表?帮我解决这个问题

【问题讨论】:

    标签: python pyqt4


    【解决方案1】:

    请使用字体monospaceconsola 或其他字体用于控制台或编程。您可以在样式表中设置;

    QTextEdit {
        font: 10pt "Consolas";
    }
    

    输入你的QTextEdit

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

    注意:QPlainTextEdit 也可以使用它,我建议仅将其用于显示原始文本并实现相同的 QTextEdit

    【讨论】:

    • 现在我有一个小问题假设现在我想将表格的内容和 qtextedit 抓取到一个文件中(基本上是将表格和 qtextedit 的内容复制到一个文件中),你能帮我怎么做这样做是因为 gettext() 方法只适用于 qlineedit,什么适用于 qtextedit @Kitsenu Meyoko
    • 复制到qtextedit,可以使用QString QTextEdit.toPlainText (self)。但在 qtable 中,您必须从 csv 中的行和列转换或自己的 excel 格式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多