move QPushButton in QGraphicsScene



  • 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


  • Qt Champions 2016

    @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.



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.