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. Multiple widget instances
QtWS25 Last Chance

Multiple widget instances

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.4k 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.
  • R Offline
    R Offline
    rpqt
    wrote on last edited by
    #1

    Hello,
    Is there a general way to have 1 model for a widget and 2 or more views, for example multiple instances of a QComboBox and all of whose values (except perhaps position,etc) of them are synchronised across the application, without having to define custom methods/delegates for each Qwidget?

    Thanks,
    rpqt

    1 Reply Last reply
    0
    • L Offline
      L Offline
      ludde
      wrote on last edited by
      #2

      Have not tried it, but I would assume setting the model of one QComboBox to the model used by another QComboBox would do exactly that. E.g.:
      @
      comboBox1->setModel(comboBox2->model());
      @
      Or, if you have created the model separately:
      @
      comboBox1->setModel(comboBoxModel);
      comboBox2->setModel(comboBoxModel);
      @
      The model can be any subclass of QAbstractItemModel.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        [quote author="rpqt" date="1331714339"]Hello,
        Is there a general way to have 1 model for a widget and 2 or more views, for example multiple instances of a QComboBox and all of whose values (except perhaps position,etc) of them are synchronised across the application, without having to define custom methods/delegates for each Qwidget?[/quote]

        Are you talking about the model/view concept of Qt?
        Or is it a different direction, you are looking at?

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rpqt
          wrote on last edited by
          #4

          Thanks @ludde and @gerolf, but what I meant was that suppose a user wanted to create a copy of a (maybe rather complex subclass of) QWidget or QGLWidget by dragging it (or a key combination) such that the new widget would (except for being located in a different place) share all the data member values etc of the first.
          Now for a combobox, as ludde mentioned, there is a set model method (under MVC) but is there a more generic way like SetWidgetModel or something (even if it is not exactly MVC) that can replicate state across 2 widgets of the same class without having to explicitly define custom methods/signals/delegates for each user interaction of such widget class or store the changed values in some data structure (for each type)?

          Thanks,
          rpqt

          1 Reply Last reply
          0
          • L Offline
            L Offline
            ludde
            wrote on last edited by
            #5

            OK, that's something much more generic, which I think will be quite difficult to accomplish, at least in a generic way. I'm pretty sure there is no built-in support for anything like that in Qt.

            For a specific QWidget subclass, I guess you can make sure that data is shared accross instances of the class, or synchronize changes by setting up signals and slots to propagate data/property changes. But this will be something you will have to do separately for/in each such QWidget subclass, since it is not really possible to know which data to synchronize and how to do it for the generic case.

            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