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. QGraphicsView custom polygon button item
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView custom polygon button item

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 497 Views 2 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.
  • H Offline
    H Offline
    hobbyProgrammer
    wrote on last edited by
    #1

    I'd like to add QPushButtons that are shaped like a polygon to my QGraphicsView.
    Is this possible and if so, how?

    They need to be able to respond to a mouse press.

    Pl45m4P 1 Reply Last reply
    0
    • H hobbyProgrammer

      I'd like to add QPushButtons that are shaped like a polygon to my QGraphicsView.
      Is this possible and if so, how?

      They need to be able to respond to a mouse press.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @hobbyProgrammer

      You dont need the QPushButton class for this...If you want to use your existing polygon items, you can make them clickable and react on mousePressEvent.

      https://doc.qt.io/qt-5/qgraphicsitem.html#mousePressEvent

      Anyway, you can change the painter from your QPushButton derived class to make it look like a polygon...but if you want to click your GraphicsView-Items, I would go with the first option.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      H 1 Reply Last reply
      1
      • Pl45m4P Pl45m4

        @hobbyProgrammer

        You dont need the QPushButton class for this...If you want to use your existing polygon items, you can make them clickable and react on mousePressEvent.

        https://doc.qt.io/qt-5/qgraphicsitem.html#mousePressEvent

        Anyway, you can change the painter from your QPushButton derived class to make it look like a polygon...but if you want to click your GraphicsView-Items, I would go with the first option.

        H Offline
        H Offline
        hobbyProgrammer
        wrote on last edited by
        #3

        @Pl45m4 So just create a custom QGraphicsPolygonItem and overwrite the mousepressevent?

        Pl45m4P 1 Reply Last reply
        0
        • H hobbyProgrammer

          @Pl45m4 So just create a custom QGraphicsPolygonItem and overwrite the mousepressevent?

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @hobbyProgrammer

          Depends on your existing GraphicItems (I guess they have a custom type, no standard Qt-class objects?)

          Something like this might work for you:

          void MyPolygonShape::mousePressEvent(QGraphicsSceneMouseEvent *event)
          {
              qDebug() << "Hello, it's me";
               // Do something here
              QGraphicsItem::mousePressEvent(event);
          }
          

          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          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