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. Overriding function from QGraphicsItemGroup without inheritance
Forum Updated to NodeBB v4.3 + New Features

Overriding function from QGraphicsItemGroup without inheritance

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.7k 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.
  • D Offline
    D Offline
    depecheSoul
    wrote on last edited by
    #1

    Hello.

    I have made a simple class GraphicsView that inherits QGraphicsView, and that class is the centry widget of MainWindow class.

    The GraphicsView class has one simple assignment: to display QGraphicsView and set QGraphicsScene on QGraphicsView. In the QGraphicsScene I have a QGraphicsItemGroup that has two QGraphicsRectItem.

    I want to when I click on QGraphicsItem that QGraphicsRectItem change one another (one is visible and red, second is not visible and blue)

    So far I have made when I click on QGraphicsView it changes, but I want to make when I click on QGraphicsItemGroup it changes.

    I know that this can be done with inhereting QGraphicsItemGroup, but I am interesting to see is this possible without inheritance.

    Thanks.

    [edit: fixed typo in title, Eddy]

    1 Reply Last reply
    0
    • W Offline
      W Offline
      Wilk
      wrote on last edited by
      #2

      Hello.
      Possible solution is to reimplement QGraphicsView's mousePressEvent. There you may use something like this:
      @
      QGraphicsItemGroup *clicked_group;
      if (clicked_goup = qgraphicsitem_cast<QGraphicsItemGroup>(scene() ->itemAt(mapToScene (event ->pos())))) {
      // Code for making different items of group (in)visible. I don't know how actualy you prefer to do it.
      }
      @

      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