Beginner: Formatting text output (PyQt4)

Tina I tinaweb at bestemselv.com
Thu Apr 19 01:53:55 EDT 2007


Glen wrote:


>> Hello again,  I don't blame anyone for not answering my last post,
> since
>> I obviously hadn't spent much time researching, but I've come a little
>> ways and have another question.
>>
>> How can I better format text output to a QTextEdit object?  I'm
>> inserting 5 columns into each row.  When I write the info to a file, it
>> looks like the following:
>>
>> 42: 115     26: 114     35: 112     19: 108     16: 107 45: 107     40:
>> 106      5: 105     41: 104      2: 103
>>  9: 102     48: 102     15: 101     22: 101     27: 101
>> 39: 101     43: 101     10: 100      6:  99     34:  99 32:  98     49:
>> 98     20:  97     30:  97      8:  96 17:  96     38:  96     12:  95
>> 14:  95     37:  95
>>  4:  94     13:  94     44:  94     36:  93      3:  92
>> 24:  92     28:  92     31:  91     29:  89      7:  88
>>  1:  87     18:  85     46:  85     33:  84     11:  83
>> 23:  83     47:  82     25:  80     21:  79     50:  56 52:  39     51:
>> 38     53:  36     54:  25     55:  18
>>
>> When I write the contents of the file to my TextEdit object it comes out
>> uneven, something like this:
>> 42: 115    26: 114    35: 112    19: 108    16: 107 45: 107    40: 106
>> 5: 105    41: 104     2: 103 9: 102    48: 102    15: 101    22: 101 27:
>> 101 39: 101    43: 101    10: 100    6:  99    34:  99 32:  98    49: 98
>>    20:  97    30:  97    8:  96 17:  96    38:  96    12:  95    14: 95
>>   37:  95 4:  94    13:  94    44:  94    36:  93    3:  92 24:  92 28:
>> 92    31:  91    29:  89    7:  88
>>  1:  87    18:  85    46:  85    33:  84    11:  83
>> 23:  83    47:  82    25:  80    21:  79    50:  56 52:  39    51:  38
>> 53:  36    54:  25    55:  18
>>
>> What seems to be happening is that the font that pyqt is using is not
>> fixed width, so I did this:
>> 	qTxtFormat = QTextCharFormat()
>> 	qTxtFormat.setFontFixedPitch(True)
>> 	ui.textEdit.setCurrentCharFormat(qTxtFormat)
>>
>> Also, I tried using the pyqt formatting such as the following:
>>
>> 	qStr = QtCore.QString( QtCore.QString( str(tL2[i][0])
>> 	).rightJustified(2) + ':' + QtCore.QString( str(tL2[i][1])
>> 	).rightJustified(4) )
>> This still gives me uneven columns.
>>
>> Any suggestions?
>>
>> Thanks,
>>
>> Glen
> 
Do you need to use QTextEdit for the output? Sounds like maybe you 
should look at for example the QTableWidget or maybe the QTreeWidget?

Tina



More information about the Python-list mailing list