Important: Please read the Qt Code of Conduct -

How to block object type QGraphicsView?

  • Hello All
    I wanna block object QGraphicsView that Nobody can click and do something on this window. Window has to be only to read.

    I used function:
    but this doesn't working
    Any Ideas?
    thanks for help and answers.

  • Moderators

    easiest way would be to set it disabled

    Or you can try the following:
    widget->setAttribute(Qt::WA_TransparentForMouseEvents, true);

  • your method doesn't working in my game :/
    I use object type QGraphicsView as board in game boats.

  • Moderators

    ok lets start from the beginning :)
    What do you exactly want to achieve?
    Let me know if i misunderstood something:

    • your window may be focusable, but no contents of it may be editable.
    • the window may be still resizeable and moveable
    • the window is a top level QGraphicsView?

    What does the QGraphicsView contain?
    What exactly doesn't work for you?
    When your graphics view contains editable items then setInteractive(false) should work. Also the disabling of the widget blocks input events for sure.

    Please show some more code if necessary.

  • this is part code which concerns object QGraphicsView in my program:

    @QGraphicsScene *scene = new QGraphicsScene(0,0,710,478);


    Exactly I want stop settings and moving ships on new place.
    Program has to working how simple game in ships.
    Program has to working how simple game in ships. When first player will select points to shot, then second must have blocked window that he will can't nothing do.
    I am thinking that now explained better my problem :)

Log in to reply