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. move QPushButton in QGraphicsScene
Qt 6.11 is out! See what's new in the release blog

move QPushButton in QGraphicsScene

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.5k 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.
  • A Offline
    A Offline
    aliks-os
    wrote on last edited by
    #1

    I add QPushButton to the QGraphicsItem as following

    actionButton = new QPushButton("ActionButton");
    actionButton->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    actionButton->setFocusPolicy(Qt::NoFocus);
    actionButton->setGeometry(QRect(25, 25,
                                         this->getWidth()-45,
                                         this->getHeight()-45));
    
    QGraphicsProxyWidget* pProxyWidget = this->scene()->addWidget(actionButton);
    pProxyWidget->setHandlesChildEvents(true);
    pProxyWidget->setParentItem(this);
    

    I can move, resize QGraphicsItem. The size of button less than QGraphicsItem. The porblem is that I want to make a Button transparent for mouse click. For example click on the button and Move/Drag it over the scene.

    Please point me to how do it or share with the correct example

    kshegunovK 1 Reply Last reply
    0
    • A aliks-os

      I add QPushButton to the QGraphicsItem as following

      actionButton = new QPushButton("ActionButton");
      actionButton->setAttribute(Qt::WA_TransparentForMouseEvents, true);
      actionButton->setFocusPolicy(Qt::NoFocus);
      actionButton->setGeometry(QRect(25, 25,
                                           this->getWidth()-45,
                                           this->getHeight()-45));
      
      QGraphicsProxyWidget* pProxyWidget = this->scene()->addWidget(actionButton);
      pProxyWidget->setHandlesChildEvents(true);
      pProxyWidget->setParentItem(this);
      

      I can move, resize QGraphicsItem. The size of button less than QGraphicsItem. The porblem is that I want to make a Button transparent for mouse click. For example click on the button and Move/Drag it over the scene.

      Please point me to how do it or share with the correct example

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @aliks-os
      Hi Alex,
      I don't think the windows attributes have any bearing on widgets that are put into a graphic scene. What I'd attempt is to intercept the mouse events from the graphics proxy widget. If I'm not in error it's the object that actually is responsible for the event dispatching when mixing widgets and graphics items. I hope that helps.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aliks-os
        wrote on last edited by
        #3

        Many thanks for your, I tried to do it, but I did not succeed.
        I decided to go the other way - it's a bit not nice, but I quickly made it right. My app has two modes: the design mode and user mode. In user mode, the button is used as a button and does not move. In design mode, the button can be moved and it is not used as a button.

        I put on top of button a QLabel. In user mode, QLabel is invisible, button is visible. In design mode - vs. In this case, everything works OK

        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