Coder Social home page Coder Social logo

QGraphicsSceneMouseEvent about qt HOT 4 CLOSED

therecipe avatar therecipe commented on September 24, 2024
QGraphicsSceneMouseEvent

from qt.

Comments (4)

therecipe avatar therecipe commented on September 24, 2024

These work for me now.

func mousePressEvent(e *widgets.QGraphicsSceneMouseEvent) {
    var color = gui.NewQColor2(160, 160, 160, 255) // r,g,b,a
    var pen = gui.NewQPen3(color)
    pen.SetWidth(1)
    var brush = gui.NewQBrush()

    scene.AddRect2(e.ScenePos().X(), e.ScenePos().Y(), 5, 10, pen, brush)
}

Or if you override the ConnectMousePressEvent on the QGraphicsView

func mousePressEvent(e *gui.QMouseEvent) {
    var color = gui.NewQColor2(160, 160, 160, 255) // r,g,b,a
    var pen = gui.NewQPen3(color)
    pen.SetWidth(1)
    var brush = gui.NewQBrush()

    var pointOnScene = view.MapToScene5(int(e.Pos().X()), int(e.Pos().Y()))
    scene.AddRect2(pointOnScene.X(), pointOnScene.Y(), 5, 10, pen, brush)
}

from qt.

5k3105 avatar 5k3105 commented on September 24, 2024

First example you gave:

    build
    output:# local/qt_test
    .\test1.go:178: cannot use e.ScreenPos().X() (type int) as type float64 in argument to scene.AddRect2
    .\test1.go:178: cannot use e.ScreenPos().Y() (type int) as type float64 in argument to scene.AddRect2

    error:exit status 2

Second example gives:

    build
    output:# local/qt_test
    .\test1.go:156: cannot use mousePressEvent (type func(*gui.QMouseEvent)) as type func(*widgets.QGraphicsSceneMouseEvent) in argument to scene.ConnectMousePressEvent

    error:exit status 2

If I use QGraphicsSceneMouseEvent instead, I get the same problem as before but in the opposite direction. Box lands top left from mouse pointer, before it landed bottom right by a few hundred pixels.

I think the Pos method is what I'm supposed to use but it's not there.

from qt.

therecipe avatar therecipe commented on September 24, 2024

Hey

Sorry, you have to sync with the repo first.

Also the first example is slightly edited and now uses e.ScenePos().X() instead of e.ScreenPos().X()
And the second example needs to be used in view.ConnectMousePressEvent (QGraphicsView)

Hope it works now ;)

from qt.

5k3105 avatar 5k3105 commented on September 24, 2024

I see now. Even when I stare at something several times I miss it. Sorry. It's working now. Thanks!

from qt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.