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. Translucent window - mouse event
Forum Updated to NodeBB v4.3 + New Features

Translucent window - mouse event

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 5.9k 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.
  • T Offline
    T Offline
    Talei
    wrote on last edited by
    #1

    Hello,
    I have translucent widget ( Qt::WA_TranslucentBackground) and I want to catch mouse press events on that widget.
    The widget is top level and I know that on Win and Mac OS I could use hook but I would prefer not to.

    Any advice are more then welcome.

    Best regards.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      EmoBemo
      wrote on last edited by
      #2

      Did you try overriding mousePressEvent() and did you set the Qt::FramelessWindowHint flag?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Talei
        wrote on last edited by
        #3

        I used event filter to do so, and checking mouse events for scene and view and the problem is that if I press on transparent area then app. don't receive mouse events, when hit on already created item then I mouse event is catch.

        On another est app I did used view mouse events, same situation.

        Update: translucent widgets are QGraphicsView and QGraphics scene.

        1 Reply Last reply
        0
        • E Offline
          E Offline
          EmoBemo
          wrote on last edited by
          #4

          Instead of setting Qt::WA_TranslucentBackground you can use setBackgroundRole(QPalette::NoRole) to make the background transparent. Then all mouse events are handled as usual.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Talei
            wrote on last edited by
            #5

            With setBackgroundRole background is not transparent in scene.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Talei
              wrote on last edited by
              #6

              Situation looks like this:

              OS: Win 8, Qt 5.2.0, 5.2.1, 5.1.1 etc. same story.

              When creating translucent window and clicking on translucent/transparent part of application mouse events are not catch by application:

              !http://www.pixentral.com/pics/1wsdglAGTp2rcFVrvqyL94OB6gmALA.jpg(a)!

              Above example illustrate situation, when clicking on window test is selected.
              What i'm looking is solution that would allow me to choose if app want's to process event, if yes then mouse press is consumed by application if no then mouse press goes to OS, and in above case text cursor is positioned on mouse position

              Any suggestions are more then welcome.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vittalonline
                wrote on last edited by
                #7

                setattribute to Qt::WA_TransparentForMouseEvents and Qt::WA_Translucentbackground.

                I hope it will solve you problem.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  JvdGlind
                  wrote on last edited by
                  #8

                  Hmm, it seems WA_TransparentForMouseEvents only works if it is not most parent widget. When adding a pushButton with that attribute set, the events are aways caught by the mainwindow, regardless if I click the button or the transparent mainwindow.

                  @#include "mainwindow.h"
                  #include "ui_mainwindow.h"

                  #include <QDebug>

                  MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::MainWindow)
                  {
                  ui->setupUi(this);

                  setAttribute(Qt::WA_TranslucentBackground, true);
                  setAttribute(Qt::WA_TransparentForMouseEvents, true);
                  ui->pushButton->setAttribute(Qt::WA_TransparentForMouseEvents, true);
                  

                  }

                  MainWindow::~MainWindow()
                  {
                  delete ui;
                  }

                  void MainWindow::mousePressEvent(QMouseEvent *)
                  {
                  qDebug() << "pressed";
                  }@

                  Jeffrey VAN DE GLIND
                  Principle Consultant @ Nalys
                  www.nalys-group.com

                  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