[PyQt] sizing a QTextEdit...

Algis Kabaila akabaila at pcug.org.au
Thu Sep 9 07:39:47 BST 2010


On Thursday 09 September 2010 14:12:00 Peter Milliken wrote:
> Sorry, that previous email should have explained that within the main
> QFrame I am attempting to lay everything out using gridlayout.
> 
> On Thu, Sep 9, 2010 at 2:06 PM, Peter Milliken 
<peter.milliken at gmail.com>wrote:
> > Probably not. The code snippet might be a bad example. I am attempting to
> > create a QFrame in the MainWindow and populate it with a number of pairs
> > of lQLabel/QLineEdit. One of the "pairs" needs to be a QLabel/QTextEdit
> > and unfortunately as soon as I add that the grid seems to 'explode' - in
> > the vertical direction.  I just want a QTextEdit sized about 3 or 4
> > times the height of a QLineEdit.
> > 
> > Thanks for the suggestion
> > Peter
> > 
> > On Thu, Sep 9, 2010 at 1:58 PM, Algis Kabaila <akabaila at pcug.org.au>wrote:
> >> On Thursday 09 September 2010 13:03:14 Peter Milliken wrote:
> >> > I cannot work out how to (re)size a QTextEdit widget. I have tried
> >> 
> >> various
> >> 
> >> > methods, without success. I show one method in the following code
> >> 
> >> snippet,
> >> 
> >> > I would appreciate it if somebody could point out my error :-)
> >> > 
> >> > Thanks
> >> > Peter
> >> > 
> >> > from PyQt4.QtCore import *
> >> > from PyQt4.QtGui import *
> >> > import PyQt4.Qt as Qt
> >> > import sys
> >> > 
> >> > class Test(QMainWindow):
> >> >   def __init__ (self, parent = None):
> >> >     super(Test, self).__init__(parent)
> >> >     self.frame = QFrame()
> >> >     self.setCentralWidget(self.frame)
> >> >     grid = QGridLayout()
> >> >     grid.addWidget(QLabel("Desc:"), 0, 0)
> >> >     self.description = QTextEdit()
> >> >     currentSize = self.description.size()
> >> >     print currentSize
> >> >     currentSize.scale(50,25, Qt.IgnoreAspectRatio)
> >> >     self.description.resize(currentSize)
> >> >     grid.addWidget(self.description, 0, 1)
> >> >     self.frame.setLayout(grid)
> >> > 
> >> > if __name__ == '__main__':
> >> >   app = QApplication(sys.argv)
> >> >   
> >> >   Gui = Test()
> >> >   Gui.show()
> >> >   app.exec_()
> >> 
> >> Would the following satisfy your immediate needs?
> >> 
> >> from PyQt4.QtGui import *
> >> import PyQt4.Qt as Qt
> >> import sys
> >> 
> >> class Test(QMainWindow):
> >>  def __init__ (self, parent = None):
> >>    super(Test, self).__init__(parent)
> >>    
> >>     self.resize(600, 300) # Added statement
> >>     self.frame = QFrame()
> >>    
> >>    self.setCentralWidget(self.frame)
> >>    grid = QGridLayout()
> >>    grid.addWidget(QLabel("Desc:"), 0, 0)
> >>    self.description = QTextEdit()
> >>    currentSize = self.description.size()
> >> 
> >> #    print currentSize
> >> #    currentSize.scale(50,25, Qt.IgnoreAspectRatio)
> >> 
> >>    self.description.resize(currentSize)
> >>    grid.addWidget(self.description, 0, 1)
> >>    self.frame.setLayout(grid)
> >> 
> >> if __name__ == '__main__':
> >>  app = QApplication(sys.argv)
> >>  Gui = Test()
> >>  Gui.show()
> >>  app.exec_()
> >> 
> >> --
> >> OldAl
> >> akabaila at pcug.org.au

I am afraid I am not competent to help you much further, because of my lack of 
knowledge of PyQt.  I do use textEdit as one main QWidget for a GUI of an 
extant Python program which I am writing, but not two textEdit's at a time.

Actually, I would like to know if it is possible to extract one line of text 
from textEdit, so I pay closer attention to questions about textEdit. Do you 
know if it can be done and if so how?

It seems that for my GUI, two textEdits could possibly be useful  - one for 
data input and one for output.  I thought of using tab widgets - each tab with 
a single textEdit for that purpose.  Just tried it out a minute ago in "Qt 
Designer".  It looks promising.

Perhaps it would be helpful to try your ideas of set out with Qt Designer?

May be you should raise the question again in a new thread as I spoiled this 
thread for you with my "cheap answer" - sorry about that!

-- 
OldAl
akabaila at pcug.org.au


More information about the PyQt mailing list