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 emit a signal to all QGraphicsRectItem

How to emit a signal to all QGraphicsRectItem

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 5 Posters 822 Views 4 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.
  • A Offline
    A Offline
    addebito
    wrote on last edited by addebito
    #1

    Hi,
    I have subclass the QGraphicsRectItem (MyQGraphicsRectItem) to produce different type of QGraphicsRectItem and I have set the flag setAcceptHoverEvents(true);
    Now, when the mouse is over on a MyQGraphicsRectItem I'd like to emit a signal to all MyQGraphicsRectItems in scene and paint the background-color red or green according to the type of MyQGraphicsRectItem.

    There is a way to emit a "signal in broadcast" to all my derived class "MyQGraphicsRectItem"?

    Thank you

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Since QGraphicsItem is not derived from QObject you can't send a signal (until you derive from QObject, but you did not mentioned it).
      Since you create the items you can put them in a container and iterate over them later on to set the appropriate flag.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

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

        This is an interesting question which seems to have a more direct answer of "no, there is no universal signal broadcast mechanism in Qt"? I believe Qt is a pure publisher/subscriber architecture.

        Could a similar effect be accomplished using framework events instead of signals?

        If you meet the AI on the road, kill it.

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

          @Kent-Dorfman It's just that it does not make sense for QGraphicsItem to be QObject based. There's a cost for that and since you may have a lot of them in a scene and usually you don't need all that machinery, it's better to keep them from being QObject based (same goes for the item classes related to QTree/QTableWidget.

          Note that there is QGraphicsObject if you need items with QObject capabilities.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          3
          • SGaistS SGaist

            @Kent-Dorfman It's just that it does not make sense for QGraphicsItem to be QObject based. There's a cost for that and since you may have a lot of them in a scene and usually you don't need all that machinery, it's better to keep them from being QObject based (same goes for the item classes related to QTree/QTableWidget.

            Note that there is QGraphicsObject if you need items with QObject capabilities.

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            @SGaist said in How to emit a signal to all QGraphicsRectItem:

            Note that there is QGraphicsObject if you need items with QObject capabilities.

            Or, if you want to keep the QGraphicsRectItem capabilities, you can derive from QObject first, QGraphicsRectItem second. Although I would probably prefer a solution not using QObject/signals, unless there is a good reason for it.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              addebito
              wrote on last edited by
              #6

              OK, thank you all very much.

              Yes, my derived class is something like that, because I need the signal/slot mechanism

              class VTGraphicsPin : public QObject, public QGraphicsRectItem
              

              I think I'll send a signal to an external class (manager) because it has a container, and iterate on all objects to check what "pin" should have the same color.

              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