Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to mirror a QWidget to two windows at once?
Forum Updated to NodeBB v4.3 + New Features

How to mirror a QWidget to two windows at once?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 363 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
    Kattia
    wrote on last edited by
    #1

    Is it possible to draw/mirror a widget into two different windows at same time?

    For example, draw the containerWidget in both windows, when i check the checkbox in one window it also would
    be checked into the second window:

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    {
        ui.setupUi(this);
        QWidget *containerWidget = new QWidget(this);
        QGridLayout *gridLayout = new QGridLayout(containerWidget);
        QCheckBox* checkbox = new QCheckBox();
        checkbox->setGeometry(50, 5, 50, 50);
        gridLayout->addWidget(checkbox);
    
    
        QMainWindow *mainWindow2 = new QMainWindow;
        mainWindow2->setCentralWidget(containerWidget);
        mainWindow2->show();
    }
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi

      I think what you are asking would imply a widget being displayed twice, which Qt has never been made for.

      I think the only solution is to instanciate the widget twice, which is what you already did, and sync them with appropriate signal and slots. Or maybe share the same data structure if this ever seems relevant.

      In your MainWindow's construtor, you would add a double connection like this

      connect (containerWidget->myCheckBox, &QCheckBox::onChecked, mainWindow2->myCheckBox, &QCheckBox::setChecked) ; 
      connect (mainWindow2->myCheckBox, &QCheckBox::onChecked, containerWidget->myCheckBox, &QCheckBox::setChecked) ; 
      

      if you ever need to emit your own signals, don't forget to check whether the value has actually changed before emitting. Otherwise you would get signals being send to each other into an infinite loop.

      1 Reply Last reply
      1
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by Kent-Dorfman
        #3

        As already stated, but to restate...No. You need to address mirroring on the X display level using someting like a screen scraping VNC server, or do what @ankou29666 mentioned and create two separate instances and link them with signals.

        1 Reply Last reply
        1

        • Login

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