Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Qt textEdit Window size
Forum Updated to NodeBB v4.3 + New Features

Qt textEdit Window size

Scheduled Pinned Locked Moved Unsolved Qt for Python
16 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KeithSloan
    wrote on last edited by KeithSloan
    #3

    Already tried

    layout.addWidget(self.textEdit,2)
    layout.addWidget(self.textMsg,1)
    

    But no change.

    Think as its a textEdit window there is a scrollArea attached and if I print out its height it is 480 pixels which what I am seeing, but no idea how to influence, tried changing various options on setSizePolicy but again no change.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @KeithSloan said in Qt textEdit Window size:

      Think as its a textEdit window there is a scrollArea attached

      This is not clear.

      Can you provide the full layout setup code ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KeithSloan
        wrote on last edited by KeithSloan
        #5

        The following code is in a FreeCAD workbench. I have no control over parent window, just want to size to what it makes available
        which varies on how the user controls various windows.

        class AddSCADWidget(QtGui.QWidget):
            def __init__(self,*args):
                QtGui.QWidget.__init__(self,*args)
                # Main text area
                self.textEdit=QtGui.QTextEdit()
                self.textEdit.setAcceptRichText(False)
                # Following line Made no difference
                self.textEdit.setMaximumHeight(4096)
                # Following made no difference also tried QSizePolicyExpanding
                self.textEdit.setSizePolicy(QtGui.QSizePolicy.Expanding, \
                           QtGui.QSizePolicy.MinimumExpanding)
                print(self.textEdit.sizePolicy())
                print(self.textEdit.sizeHint())
                print(self.textEdit.viewport())
                vp = self.textEdit.viewport()
                print(vp.maximumHeight())
                print(vp.height())
                print(vp.sizeHint())
                # following did not make any difference
                vp.setSizePolicy(QtGui.QSizePolicy.Expanding, \
                           QtGui.QSizePolicy.Expanding)
                print(vp.sizePolicy()
                # Message Area
                self.textMsg=QtGui.QPlainTextEdit()
                self.textMsg.setReadOnly(True)
                h = int(2.5 * self.textMsg.fontMetrics().height())
                self.textMsg.setMaximumHeight(h)
                self.textMsg.resize(self.textMsg.width(),h)
                self.buttonadd = QtGui.QPushButton(translate('OpenSCAD','Add'))
                self.buttonclear = QtGui.QPushButton(translate('OpenSCAD','Clear'))
                self.buttonload = QtGui.QPushButton(translate('OpenSCAD','Load'))
                self.buttonsave = QtGui.QPushButton(translate('OpenSCAD','Save'))
                self.buttonrefresh = QtGui.QPushButton(translate('OpenSCAD','Refresh'))
                self.checkboxmesh = QtGui.QCheckBox(translate('OpenSCAD','as Mesh'))
                layouth=QtGui.QHBoxLayout()
                layouth.addWidget(self.buttonadd)
                layouth.addWidget(self.buttonload)
                layouth.addWidget(self.buttonsave)
                layouth.addWidget(self.buttonrefresh)
                layouth.addWidget(self.buttonclear)
                layout= QtGui.QVBoxLayout()
                layout.addLayout(layouth)
                layout.addWidget(self.checkboxmesh)
                #layout.addWidget(self.textEdit, 6)
                #layout.addWidget(self.textMsg, 1)
                layout.addWidget(self.textEdit)
                layout.addWidget(self.textMsg)
                layout.setStretch(0,0)
                layout.setStretch(1,0)
                layout.setStretch(2,1)
                layout.setStretch(3,0)
                self.setLayout(layout)
                self.setWindowTitle(translate('OpenSCAD','Add OpenSCAD Element'))
                self.textEdit.setText(u'cube();')
                self.buttonclear.clicked.connect(self.textEdit.clear)
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #6

          What do you get if you use just this:

          class AddSCADWidget(QtGui.QWidget):
              def __init__(self,*args):
                  QtGui.QWidget.__init__(self,*args)
                  # Main text area
                  self.textEdit=QtGui.QTextEdit()
                  # Message Area
                  self.textMsg=QtGui.QPlainTextEdit()
                  self.textMsg.setReadOnly(True)
                  h = int(2.5 * self.textMsg.fontMetrics().height())
                  self.textMsg.setMaximumHeight(h)
            
                  layout= QtGui.QVBoxLayout(self)
                  layout.addWidget(self.textEdit, 2)
                  layout.addWidget(self.textMsg, 1)
          

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          K 1 Reply Last reply
          0
          • SGaistS SGaist

            What do you get if you use just this:

            class AddSCADWidget(QtGui.QWidget):
                def __init__(self,*args):
                    QtGui.QWidget.__init__(self,*args)
                    # Main text area
                    self.textEdit=QtGui.QTextEdit()
                    # Message Area
                    self.textMsg=QtGui.QPlainTextEdit()
                    self.textMsg.setReadOnly(True)
                    h = int(2.5 * self.textMsg.fontMetrics().height())
                    self.textMsg.setMaximumHeight(h)
              
                    layout= QtGui.QVBoxLayout(self)
                    layout.addWidget(self.textEdit, 2)
                    layout.addWidget(self.textMsg, 1)
            
            K Offline
            K Offline
            KeithSloan
            wrote on last edited by
            #7

            @SGaist ![alt text](0A1236B7-6660-4629-8F8C-ED3A472CD06C.jpeg image url)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              It looks like you only have access to half a widget ?
              That's strange, what if you add self.textEdit.setMinimumHeight(4096) ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • K Offline
                K Offline
                KeithSloan
                wrote on last edited by
                #9

                Setting minimumHeight(4096) ( And removing message Window ) still does not expand the the textEdit![alt text](FC6D9F1C-633F-47C7-AEB9-DC41EA9E22B0.jpeg image url)

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  This is getting stranger and stranger... what if you use setFixedSize ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  K 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    This is getting stranger and stranger... what if you use setFixedSize ?

                    K Offline
                    K Offline
                    KeithSloan
                    wrote on last edited by KeithSloan
                    #11

                    @SGaist My Bad minimumHeight gave me
                    ![alt text](8E9C12E9-4C7E-4F38-8BD7-F96CA767CF4C.jpeg image url)

                    So I have to some how get the parent window size and calculate the size? Or is there a better way?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      You shouldn't need to do that.

                      How are you integrating your code with FreeCAD ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        KeithSloan
                        wrote on last edited by
                        #13

                        It is a FreeCAD workbench so it exists in a subdirectory of Mod in the FreeCAD file structure and as FreeCAD finds a InitGui.py and Init.py file it gets invoked. When the user selects the workbench in this case OpenSCAD it gets started, which registers a number of icons. Press on one of these icons invokes code that creates the boxes in one of the FreeCAD windows, the window can vary in size depending on users monitor, whether is has the Combo View panel displayed and can adjust the size of the Combo window.

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          KeithSloan
                          wrote on last edited by
                          #14
                          class AddSCADTask:
                              def __init__(self):
                                  self.form = AddSCADWidget()
                          
                          class AddSCADWidget(QtGui.QWidget):
                              def __init__(self,*args):
                                  QtGui.QWidget.__init__(self,*args)
                                  # Main text area
                                  self.textEdit=QtGui.QTextEdit()
                                  .... etc ...
                          
                          class AddOpenSCADElement:
                              def IsActive(self):
                                  return not FreeCADGui.Control.activeDialog()
                          
                              def Activated(self):
                                  panel = AddSCADTask()
                                  FreeCADGui.Control.showDialog(panel)
                          
                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            KeithSloan
                            wrote on last edited by KeithSloan
                            #15

                            Okay in AddSCADTask I added a print(dir(self.form) and got

                            19:54:00  ['DrawChildren', 'DrawWindowBackground', 'IgnoreMask', 'PaintDeviceMetric', 'PdmDepth', 'PdmDevicePixelRatio',
                            
                             'PdmDevicePixelRatioScaled', 'PdmDpiX', 'PdmDpiY', 'PdmHeight', 'PdmHeightMM', 'PdmNumColors', 'PdmPhysicalDpiX', 
                            
                            'PdmPhysicalDpiY', 'PdmWidth', 'PdmWidthMM', 'RenderFlag', 'RenderFlags', '__class__', '__delattr__', '__dict__', '__dir__',
                            
                            
                             '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', 
                            
                            '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', 
                            
                            '__subclasshook__', 'acceptDrops', 'accessibleDescription', 'accessibleName', 'actionEvent', 'actions', 'activateWindow', 'addAction', 
                            
                            'addActions', 'adjustSize', 'autoFillBackground', 'backgroundRole', 'backingStore', 'baseSize', 'blockSignals', 'changeEvent', 'childAt', 
                            
                            'childEvent', 'children', 'childrenRect', 'childrenRegion', 'clearFocus', 'clearMask', 'close', 'closeEvent', 'colorCount', 'connect', 
                            
                            'connectNotify', 'contentsMargins', 'contentsRect', 'contextMenuEvent', 'contextMenuPolicy', 'create', 'createWinId', 
                            
                            'createWindowContainer', 'cursor', 'customContextMenuRequested', 'customEvent', 'deleteLater', 'depth', 'destroy', 'destroyed', 
                            
                            'devType', 'devicePixelRatio', 'devicePixelRatioF', 'devicePixelRatioFScale', 'disconnect', 'disconnectNotify', 'dragEnterEvent', 
                            
                            'dragLeaveEvent', 'dragMoveEvent', 'dropEvent', 'dumpObjectInfo', 'dumpObjectTree', 'dynamicPropertyNames', 'effectiveWinId', 'emit', 
                            
                            'ensurePolished', 'enterEvent', 'event', 'eventFilter', 'find', 'findChild', 'findChildren', 'focusInEvent', 'focusNextChild', 'focusNextPrevChild', 
                            
                            'focusOutEvent', 'focusPolicy', 'focusPreviousChild', 'focusProxy', 'focusWidget', 'font', 'fontInfo', 'fontMetrics', 'foregroundRole', 
                            
                            'frameGeometry', 'frameSize', 'geometry', 'getContentsMargins', 'grab', 'grabGesture', 'grabKeyboard', 'grabMouse', 'grabShortcut', 
                            
                            'graphicsEffect', 'graphicsProxyWidget', 'hasFocus', 'hasHeightForWidth', 'hasMouseTracking', 'hasTabletTracking', 'height', 
                            
                            'heightForWidth', 'heightMM', 'hide', 'hideEvent', 'inherits', 'initPainter', 'inputMethodEvent', 'inputMethodHints', 'inputMethodQuery', 
                            
                            'insertAction', 'insertActions', 'installEventFilter', 'internalWinId', 'isActiveWindow', 'isAncestorOf', 'isEnabled', 'isEnabledTo', 
                            
                            'isEnabledToTLW', 'isFullScreen', 'isHidden', 'isLeftToRight', 'isMaximized', 'isMinimized', 'isModal', 'isRightToLeft', 'isSignalConnected', 
                            
                            'isTopLevel', 'isVisible', 'isVisibleTo', 'isWidgetType', 'isWindow', 'isWindowModified', 'isWindowType', 'keyPressEvent', 'keyReleaseEvent', 
                            
                            'keyboardGrabber', 'killTimer', 'layout', 'layoutDirection', 'leaveEvent', 'locale', 'logicalDpiX', 'logicalDpiY', 'lower', 'mapFrom', 
                            
                            'mapFromGlobal', 'mapFromParent', 'mapTo', 'mapToGlobal', 'mapToParent', 'mask', 'maximumHeight', 'maximumSize', 
                            
                            'maximumWidth', 'metaObject', 'metric', 'minimumHeight', 'minimumSize', 'minimumSizeHint', 'minimumWidth', 
                            
                            'mouseDoubleClickEvent', 'mouseGrabber', 'mouseMoveEvent', 'mousePressEvent', 'mouseReleaseEvent', 'move', 'moveEvent', 
                            
                            'moveToThread', 'nativeEvent', 'nativeParentWidget', 'nextInFocusChain', 'normalGeometry', 'objectName', 'objectNameChanged', 
                            
                            'overrideWindowFlags', 'overrideWindowState', 'paintEngine', 'paintEvent', 'painters', 'paintingActive', 'palette', 'parent', 'parentWidget', 
                            
                            'physicalDpiX', 'physicalDpiY', 'pos', 'previousInFocusChain', 'property', 'raise_', 'receivers', 'rect', 'redirected', 'registerUserData', 
                            
                            'releaseKeyboard', 'releaseMouse', 'releaseShortcut', 'removeAction', 'removeEventFilter', 'render', 'repaint', 'resize', 'resizeEvent', 
                            
                            'restoreGeometry', 'retranslateUi', 'saveGeometry', 'scroll', 'sender', 'senderSignalIndex', 'setAcceptDrops', 'setAccessibleDescription', 
                            
                            'setAccessibleName', 'setAttribute', 'setAutoFillBackground', 'setBackgroundRole', 'setBaseSize', 'setContentsMargins', 
                            
                            'setContextMenuPolicy', 'setCursor', 'setDisabled', 'setEnabled', 'setFixedHeight', 'setFixedSize', 'setFixedWidth',...
                            
                            19:54:00  
                            

                            Does that help at all?

                            Sorry don't know how to edit this so its not all on one line.

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #16

                              Is there a documentation that describes the process to do that task ? I think you might be missing some minor details to get your widget rendered correctly.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved