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. [SOLVED] QWidget - make a part transparent for mouse event,
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QWidget - make a part transparent for mouse event,

Scheduled Pinned Locked Moved General and Desktop
17 Posts 2 Posters 10.2k 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.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #4

    Hey SGaist,

    EventFilter are really interesting and powerful, I will use them more often.

    I have set up my RepeatWidget events to be filtered by my tableView eventFilter. But it seems my widget only trigger "Enter" and "Leave" events. I don't have the mouseMoveEvent by default?

    Thanks!

    Here is the code :

    Set up object to use eventFilter:
    @ RepeatWidget *repeatWidgetCopy = new RepeatWidget(repData, ui->tableView->viewport());
    repeatWidgetCopy->setMouseTracking(true);
    repeatWidgetCopy->installEventFilter(ui->tableView);

    ui->tableView->horizontalHeader()->setMouseTracking(true);
    ui->tableView->verticalHeader()->setMouseTracking(true);
    connect(ui->tableView, SIGNAL(entered(QModelIndex)), ui->tableView, SLOT(setCursor(QModelIndex)) );
    ui->tableView->horizontalHeader()->installEventFilter(ui->tableView);
    ui->tableView->verticalHeader()->installEventFilter(ui->tableView);@
    

    eventFilter:
    @bool TableViewInterval::eventFilter(QObject *watched, QEvent *event) {

    qDebug() << "watched object" << watched << "event:" << event << "eventType" << event->type();
    
    
    /// Change cursor to normal when hovering on Headers;
    if(qobject_cast<QHeaderView*>(watched) != nullptr && event->type() == QEvent::HoverMove)
    {
        qDebug() << "HoverMove" << watched;
        QApplication::setOverrideCursor(Qt::ArrowCursor);
    }
    
    else if (watched->objectName() == "RepeatWidget")
    {
        qDebug() << " got here now Repeat_Widget" << event->type() << event;
        if (event->type() == QEvent::MouseMove) {
            qDebug() << "RepeatWidget Mouse move now!";
            /// Check position to see if we are at column 0, if so, change cursor
            QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event);
            QPoint pos = mouseMoveEvent->pos();
            qDebug() << "pos" << pos;
            //        QModelIndex index = ui->tableView->indexAt(pos);
            //        int row = index.row();
            //        if (index.isValid())
            //        {
            //            qDebug() << "index is" << row;
    
        }
    
    }
    
    return false;
    

    }
    @


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on last edited by
      #5

      Problem seems to be with the custom QWidget that trigger MouseMove only once when it enter the Widget, but doesn't trigger more when I move inside the Widget itself

      log :
      watched object RepeatWidget(0x3d3c510, name = "RepeatWidget") event: QMouseEvent(MouseMove, 0, 0, 0) eventType 5
      RepeatWidget Mouse move now!
      pos QPoint(516,73)


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #6

        mouseMove event is only called if you are keeping a mouse button pressed. The other way to get the mouse move event continuously is to use setMouseGrabEnabled but have a look at the documentation before using it

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maximus
          wrote on last edited by
          #7

          Yo SGaist,
          Been lazy, I redesigned a new QWidget containing 2 QWidgets, one of the left with transparent mouse event and the one of the left with the controls can still get the mouse events:

          Here it is if it can help anyone:
          https://www.dropbox.com/s/66mp8rj9g4ybtw0/interfaceRepeat22.png

          Only thing to fix is a small gap in the border of the two QWidget frame, even with 0 margin they are not close enough, will investigate..
          thanks for the help!


          Free Indoor Cycling Software - https://maximumtrainer.com

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #8

            Did you also set the spacing to 0 ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maximus
              wrote on last edited by
              #9

              Yeah all the Layout have 0 margins and spacing, there must be another element that factor in.. it's like a 1mm margin, the QWidget are not touching but almost.. weird

              I tried negative margin on the layouts but not working so far,
              Thanks


              Free Indoor Cycling Software - https://maximumtrainer.com

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #10

                The space doesn't mean the widget's not right. Are you giving him a fixed size ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  maximus
                  wrote on last edited by
                  #11

                  The SizePolicy is set to minimumExpending (horizontal and vertical), not fixed.

                  The size is set dynamicly at run time when user press a button this is called :
                  Here it is :

                  @ RepeatData *repData = new RepeatData(id, firstRow, lastRow, numberRepeat);
                  RepeatWidget *repeatWidgetCopy = new RepeatWidget(repData, ui->tableView->viewport());
                  repeatWidgetCopy->move(rectCompleteSelection.topLeft());
                  repeatWidgetCopy->resize(rectCompleteSelection.size().width() + 190, rectCompleteSelection.size().height());
                  repeatWidgetCopy->show();@

                  Also some attribute that may interest you :

                  @ ui->widget_left->setAttribute(Qt::WA_TransparentForMouseEvents);
                  setAttribute(Qt::WA_TranslucentBackground);
                  setWindowFlags(Qt::FramelessWindowHint );@

                  Except that, it's a standard QWidget containing 2 QWidget that have a stylsheet with a border-color. Thanks!


                  Free Indoor Cycling Software - https://maximumtrainer.com

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    Can you show the left widget not transparent just to see how far it goes ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      maximus
                      wrote on last edited by
                      #13

                      Hmm not sure what you mean, the widget is transparent only for mouse event, both widget just have a border, no background
                      https://www.dropbox.com/s/66mp8rj9g4ybtw0/interfaceRepeat22.png

                      Thanks


                      Free Indoor Cycling Software - https://maximumtrainer.com

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        Sorry, I meant translucent

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          maximus
                          wrote on last edited by
                          #15

                          yeah this flag doesn't do much actually, same thing commented or not :/


                          Free Indoor Cycling Software - https://maximumtrainer.com

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            maximus
                            wrote on last edited by
                            #16

                            It's not a major bug, I may change the design to show a verital doted line between both widget, I'll see if I can't fix it i'll change it, thanks


                            Free Indoor Cycling Software - https://maximumtrainer.com

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              maximus
                              wrote on last edited by
                              #17

                              To have two QFrame without space between them:
                              this code worked (added 0px border because default is 1px I think, that was the problem!)

                              @#frame_border_left {

                              border-left : 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));
                              border-top: 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));
                              border-bottom: 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));
                              border-right : 0px;

                              }

                              #frame_border_right {

                              border-left : 0px;
                              border-right : 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));
                              border-top: 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));
                              border-bottom: 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));

                              }@


                              Free Indoor Cycling Software - https://maximumtrainer.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