[PyQt] Auto Fit in QTextEdit
celsowm
celsowm at gmail.com
Wed Dec 17 15:34:25 GMT 2008
Hi Everyone, i tried this, but I did not have a good result...
import sys,os
from PyQt4.QtGui import *
from PyQt4.QtCore import *
## This a sample class for tests with visualeditor
#
#
class ChangingSong(QWidget):
## The constructor
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.setGeometry(300,200,250, 150)
self.lyricsEdit = QTextEdit(self)
self.lyricsEdit.setGeometry(QRect(0, 0, 250, 150))
self.lyricsEdit.setObjectName("lyricsEdit")
self.lyricsEdit.setFontPointSize(18)
self.connect(self.lyricsEdit,
SIGNAL("textChanged()"), self.fit)
## Fit the text in lyricsEdit
# @param self The object pointer.
def fit(self):
font = self.lyricsEdit.currentFont()
font_metrics = QFontMetrics(font)
ret = font_metrics.boundingRect(self.lyricsEdit.toPlainText())
if ret.width() > self.lyricsEdit.width():
ret = font_metrics.boundingRect(self.lyricsEdit.toPlainText())
self.lyricsEdit.setFontPointSize(self.lyricsEdit.fontPointSize()-1)
#print ret.width()
#print self.lyricsEdit.width()
app = QApplication(sys.argv)
qb = ChangingSong()
qb.show()
sys.exit(app.exec_())
--
View this message in context: http://www.nabble.com/Auto-Fit-in-QTextEdit-tp21054565p21054565.html
Sent from the PyQt mailing list archive at Nabble.com.
More information about the PyQt
mailing list