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. Combine 2 windows to 1 windows
QtWS25 Last Chance

Combine 2 windows to 1 windows

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 3 Posters 376 Views
  • 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.
  • H Offline
    H Offline
    henpokpok
    wrote on last edited by henpokpok
    #1

    I have a little problem about my sat thing, I have 2 windows the first one is a map ui, the second one is a ui that will show gyroscope status, but I wanted to combine these two to a single window, how do I do that?

    Gyroscope Code :

    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import axes3d
    
    # Define the gyroscope's angular position and velocity
    theta = np.pi / 3  # Angle of rotation about the vertical axis
    omega = 0.5  # Angular velocity about the vertical axis
    
    # Create the figure
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    
    # Set the plot limits
    ax.set_xlim(-2, 2)
    ax.set_ylim(-2, 2)
    ax.set_zlim(-2, 2)
    
    # Set the plot labels
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    
    # Set the plot title
    ax.set_title('3D Gyroscope')
    
    # Add the gyroscope to the plot
    # The gyroscope is represented by a disk in the XY plane and a vertical line
    # The disk is rotated about the vertical axis according to theta
    # The vertical line is rotated about the origin according to omega
    x, y = np.meshgrid(np.linspace(-1, 1, 20), np.linspace(-1, 1, 20))
    ax.plot_surface(x * np.cos(theta) - y * np.sin(theta), x * np.sin(theta) + y * np.cos(theta), np.zeros_like(x), alpha=0.5)
    ax.plot([0, np.sin(omega)], [0, -np.cos(omega)], [0, 0], 'k-')
    
    # Show the plot
    plt.show()
    

    Map UI code :

    import sys
    from PyQt5.QtCore import QUrl
    from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
    from PyQt5.QtWebEngineWidgets import QWebEngineView
    
    # Obtain the satellite's current coordinates
    lat = 51.5074
    lon = -0.1278
    
    # Create a widget to hold the map
    class MapWidget(QWidget):
        def __init__(self):
            super().__init__()
            self.initUI()
    
        def initUI(self):
            # Create a web engine view to display the map
            self.view = QWebEngineView()
    
            # Create the URL object
            url = QUrl(f"https://www.openstreetmap.org/#map=12/{lat}/{lon}")
            
            # Load the URL into the web engine view
            self.view.load(url)
    
            # Add the web engine view to the layout
            layout = QVBoxLayout()
            layout.addWidget(self.view)
            self.setLayout(layout)
    
    # Create the application and the map widget
    app = QApplication(sys.argv)
    widget = MapWidget()
    widget.show()
    sys.exit(app.exec_())
    
    jsulmJ 1 Reply Last reply
    0
    • H henpokpok

      I have a little problem about my sat thing, I have 2 windows the first one is a map ui, the second one is a ui that will show gyroscope status, but I wanted to combine these two to a single window, how do I do that?

      Gyroscope Code :

      import numpy as np
      import matplotlib.pyplot as plt
      from mpl_toolkits.mplot3d import axes3d
      
      # Define the gyroscope's angular position and velocity
      theta = np.pi / 3  # Angle of rotation about the vertical axis
      omega = 0.5  # Angular velocity about the vertical axis
      
      # Create the figure
      fig = plt.figure()
      ax = fig.add_subplot(111, projection='3d')
      
      # Set the plot limits
      ax.set_xlim(-2, 2)
      ax.set_ylim(-2, 2)
      ax.set_zlim(-2, 2)
      
      # Set the plot labels
      ax.set_xlabel('X')
      ax.set_ylabel('Y')
      ax.set_zlabel('Z')
      
      # Set the plot title
      ax.set_title('3D Gyroscope')
      
      # Add the gyroscope to the plot
      # The gyroscope is represented by a disk in the XY plane and a vertical line
      # The disk is rotated about the vertical axis according to theta
      # The vertical line is rotated about the origin according to omega
      x, y = np.meshgrid(np.linspace(-1, 1, 20), np.linspace(-1, 1, 20))
      ax.plot_surface(x * np.cos(theta) - y * np.sin(theta), x * np.sin(theta) + y * np.cos(theta), np.zeros_like(x), alpha=0.5)
      ax.plot([0, np.sin(omega)], [0, -np.cos(omega)], [0, 0], 'k-')
      
      # Show the plot
      plt.show()
      

      Map UI code :

      import sys
      from PyQt5.QtCore import QUrl
      from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
      from PyQt5.QtWebEngineWidgets import QWebEngineView
      
      # Obtain the satellite's current coordinates
      lat = 51.5074
      lon = -0.1278
      
      # Create a widget to hold the map
      class MapWidget(QWidget):
          def __init__(self):
              super().__init__()
              self.initUI()
      
          def initUI(self):
              # Create a web engine view to display the map
              self.view = QWebEngineView()
      
              # Create the URL object
              url = QUrl(f"https://www.openstreetmap.org/#map=12/{lat}/{lon}")
              
              # Load the URL into the web engine view
              self.view.load(url)
      
              # Add the web engine view to the layout
              layout = QVBoxLayout()
              layout.addWidget(self.view)
              self.setLayout(layout)
      
      # Create the application and the map widget
      app = QApplication(sys.argv)
      widget = MapWidget()
      widget.show()
      sys.exit(app.exec_())
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @henpokpok Your first window has nothing to do with Qt. You would need to embed it into your Qt UI. See https://forum.qt.io/topic/44091/embed-an-application-inside-a-qt-window-solved

      Please post code as text, not images.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      H 2 Replies Last reply
      1
      • jsulmJ jsulm

        @henpokpok Your first window has nothing to do with Qt. You would need to embed it into your Qt UI. See https://forum.qt.io/topic/44091/embed-an-application-inside-a-qt-window-solved

        Please post code as text, not images.

        H Offline
        H Offline
        henpokpok
        wrote on last edited by
        #3

        @jsulm ok, ill edit the image

        1 Reply Last reply
        0
        • jsulmJ jsulm

          @henpokpok Your first window has nothing to do with Qt. You would need to embed it into your Qt UI. See https://forum.qt.io/topic/44091/embed-an-application-inside-a-qt-window-solved

          Please post code as text, not images.

          H Offline
          H Offline
          henpokpok
          wrote on last edited by
          #4

          @jsulm I'm very new to this, where is the part that will create a embed?

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

            Hi,

            The most simple is to follow the matplotlib documentation to integrate it with Qt.

            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