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. Issues with textedit not working when creating a class for subwindows
Forum Updated to NodeBB v4.3 + New Features

Issues with textedit not working when creating a class for subwindows

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 221 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.
  • P Offline
    P Offline
    Pixelhead120
    wrote on last edited by
    #1

    Hi I hope I have this right, I'm having a problem where I am using the 'Class Document' to setup subwindows which on selecting 'Add Window' subwindows are added to MainWindow's MdiArea. All good, but having used setWidget as a textedit when I run the code I cannot carry out any editing in the subwindow as it appears the textedit is not there. Can anyone assist me please?

    import sys
    from PyQt6.QtWidgets import QMainWindow, QApplication, QMdiArea, QMdiSubWindow, QTextEdit, QWidget
    from PyQt6.QtGui import QAction
    
    
    class MainWindow(QMainWindow):
        count = 0
        def __init__(self):
            super(MainWindow, self).__init__()
            self.mdi = QMdiArea()
            self.setCentralWidget(self.mdi)
            bar = self.menuBar()
            file = bar.addMenu("Add Window")
            file.addAction("window")
            file.triggered[QAction].connect(self.click)
            self.setWindowTitle("Multiple window using MDI")
    
        def click(self, event):
            print("New sub window")
            if event.text() == "window":
                test = Document()
                f = self.mdi.addSubWindow(test)
                f.show()
    
    
    class Document(QWidget):
        count = 0
        def __init__(self):
            super().__init__()
    
            self.filenew = QMdiSubWindow()
            self.textEdit = QTextEdit()
            self.filenew.setWidget(self.textEdit)
            self.setFixedSize(400, 400)
            MainWindow.count += 1
            self.setWindowTitle(f"Untitled {MainWindow.count}")
    
    def main():
        app = QApplication(sys.argv)
        window = MainWindow()
        window.show()
        sys.exit(app.exec())
    
    if __name__ == '__main__':
        main()
    

    Thanks Pixelhead120

    JonBJ 1 Reply Last reply
    0
    • P Pixelhead120

      Hi I hope I have this right, I'm having a problem where I am using the 'Class Document' to setup subwindows which on selecting 'Add Window' subwindows are added to MainWindow's MdiArea. All good, but having used setWidget as a textedit when I run the code I cannot carry out any editing in the subwindow as it appears the textedit is not there. Can anyone assist me please?

      import sys
      from PyQt6.QtWidgets import QMainWindow, QApplication, QMdiArea, QMdiSubWindow, QTextEdit, QWidget
      from PyQt6.QtGui import QAction
      
      
      class MainWindow(QMainWindow):
          count = 0
          def __init__(self):
              super(MainWindow, self).__init__()
              self.mdi = QMdiArea()
              self.setCentralWidget(self.mdi)
              bar = self.menuBar()
              file = bar.addMenu("Add Window")
              file.addAction("window")
              file.triggered[QAction].connect(self.click)
              self.setWindowTitle("Multiple window using MDI")
      
          def click(self, event):
              print("New sub window")
              if event.text() == "window":
                  test = Document()
                  f = self.mdi.addSubWindow(test)
                  f.show()
      
      
      class Document(QWidget):
          count = 0
          def __init__(self):
              super().__init__()
      
              self.filenew = QMdiSubWindow()
              self.textEdit = QTextEdit()
              self.filenew.setWidget(self.textEdit)
              self.setFixedSize(400, 400)
              MainWindow.count += 1
              self.setWindowTitle(f"Untitled {MainWindow.count}")
      
      def main():
          app = QApplication(sys.argv)
          window = MainWindow()
          window.show()
          sys.exit(app.exec())
      
      if __name__ == '__main__':
          main()
      

      Thanks Pixelhead120

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Pixelhead120
      Lost in your Document class. It's a QWidget, which then has a QMdiSubWindow in it plus a QTextEdit?

      When you use self.mdi.addSubWindow() look at examples at https://doc.qt.io/qt-5/qmdiarea.html#addSubWindow. You just pass it the widget you want added. That might be your QTextEdit if that is all you want on your subwindow, or it might be, say, a QWidget onto which you add layouts and other widgets. You certainly won't want any QMdiSubWindow(), QMdiArea::addSubWindow() creates that around the widget you pass it and returns that QMdiSubWindow it created, if you want it.

      1 Reply Last reply
      2

      • Login

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