Combine 2 windows to 1 windows
-
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_())
-
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_())
@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.
-
@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.
-
@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.
-
Hi,
The most simple is to follow the matplotlib documentation to integrate it with Qt.