Pergunta

Is there easy way to set height and width of QTextEdit so text in it is wrapped? I need functionality like this one in QLabel: label.wordWrap(true)

I have QTableWidget's cells populated with very large strings(with '\n' in them) . I found out that scrolling is very slow in case I set it with:

1.

table.setItem( i, j, QtGui.QTableWidgetItem(largeText))
table.resizeRowsToContents()
table.resizeColumnssToContents()

or 2.

label = QtGui.QLabel()
label.setText(largeText)
label.wordWrap(true)                       
table.setCellWidget(i,j,label)

but no matter how big QTextEdit is in QTableWidget's cell, scrolling goes very smootly.

Problem is I dont know how to set it to wrap text in it. help me please

Foi útil?

Solução

I've kinda hard coded this:

longestLineLength = 0
for line in text.split("\n"):
    linelength = len(line)
    if linelength >longestLineLength :
        longestLineLength = linelength 

numOfLinesInText = text.count("\n") + 2

textEdit.setFixedHeight(numOfLinesInText*15)
textEdit.setFixedWidth(longestLineLength*5.7)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top