Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This C++ code will help you connect signals and slots between all instances of a Window
- /// This function is called when MainWindow is created
- void MainWindow::MainWindow()
- {
- // Identify this QObject as "MainWindow", this helps the program know which widgets are "MainWindow"
- setObjectName("MainWindow");
- // This is a personal preference, you can ignore it if you want
- setAttribute(Qt::WA_DeleteOnClose);
- // Show the window (you can ignore this if the MainWindow is shown directly in you main.cpp file)
- show();
- }
- /// This function is called when a new window is created
- void MainWindow::CreateNewMainWindow(MainWindow *Window)
- {
- // Connect the slots that update and apply the settings between this MainWindow and the newly created one (you can change the signals and slots according to your needs)
- connect(Window, SIGNAL(UpdateSettings()), this, SLOT(ApplySettings()));
- connect(this, SIGNAL(UpdateSettings()), Window, SLOT(ApplySettings()));
- // Connect the same slots on all the remaining instances of MainWindow (you can change the signals and slots according to your needs)
- foreach(QWidget *Widget, QApplication::topLevelWidgets())
- {
- if(Widget->objectName() == "MainWindow")
- {
- connect(Widget, SIGNAL(UpdateSettings()), Window, SLOT(ApplySettings()));
- connect(Window, SIGNAL(UpdateSettings()), Widget, SLOT(ApplySettings()));
- }
- }
- // Copy the geometry of the original window into the new window
- Window->setGeometry(x(), y(), width(), height());
- // Move the window a little bit (so that both windows are visible)
- Window->move(x() + 50, y() + 50);
- // Show the new window
- Window->show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement