[Question] Mouse Over Dockwidget

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

[Question] Mouse Over Dockwidget

Post by HakanSeven12 »

I'm working on autocad like autohide. How to detect mouse over combo or other dock widgets?



combo.png
combo.png (19.47 KiB) Viewed 554 times
Last edited by HakanSeven12 on Sat Mar 28, 2020 10:18 am, edited 4 times in total.
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: [Question] Mouse Over Dockwidget

Post by HakanSeven12 »

image added
mario52
Veteran
Posts: 4690
Joined: Wed May 16, 2012 2:13 pm

Re: [Question] Mouse Over Dockwidget

Post by mario52 »

Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: [Question] Mouse Over Dockwidget

Post by HakanSeven12 »

mario52 wrote: Sat Mar 28, 2020 10:43 am hi

https://doc.qt.io/qt-5/qwidget.html#underMouse

mario
If I create a dock widget I can use it. Also I can use enterEvent and leaveEvent. But when I get combo view how can I add it to event?
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Question] Mouse Over Dockwidget

Post by openBrain »

You need to use installEventFilter() on the dock widget. ;)
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: [Question] Mouse Over Dockwidget

Post by HakanSeven12 »

openBrain wrote: Sat Mar 28, 2020 12:16 pm You need to use installEventFilter() on the dock widget. ;)
tried something but dont work :)

Code: Select all

from PySide2 import QtCore, QtGui, QtWidgets

mv = FreeCADGui.getMainWindow()
combo = mv.findChild(QtWidgets.QDockWidget, "Combo View")

class autoHide(QtWidgets.QWidget):
    def __init__(self):
        QtWidgets.QWidget.__init__(self)
        combo.installEventFilter(self)

    def eventFilter(self, source, event):
        if source is combo:
            if event.type() == event.Enter:
                print ("Mouse Entered")
                self.target.setFeatures = self.oldFeatures
                return True
            elif event.type() == event.Leave:
                print("Mouse Left")
                return True
            return super(autoHide, self).eventFilter(source, event)
                
autoHide().show()
Last edited by HakanSeven12 on Sat Mar 28, 2020 1:37 pm, edited 1 time in total.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Question] Mouse Over Dockwidget

Post by openBrain »

The main problem IMO is that your class instance is initialized without parent and thus I think is automatically destroyed :

Code: Select all

from PySide import QtCore, QtGui

class autoHide(QtCore.QObject):
    def __init__(self):
        mv = FreeCADGui.getMainWindow()
        self.target = mv.findChild(QtGui.QDockWidget, "Combo View")
        super(autoHide, self).__init__(self.target)
        self.target.installEventFilter(self)

    def eventFilter(self, source, event):
        if source is self.target:
            if event.type() == event.Enter:
                print ("Mouse Entered")
                return True
            elif event.type() == event.Leave:
                print("Mouse Left")
                return True
        return super(autoHide, self).eventFilter(source, event)

autoHide()
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: [Question] Mouse Over Dockwidget

Post by HakanSeven12 »

openBrain wrote: Sat Mar 28, 2020 1:22 pm The main problem IMO is that your class instance is initialized without parent and thus I think is automatically destroyed
thanks :D Its work
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: [Question] Mouse Over Dockwidget

Post by HakanSeven12 »

Result

Test3.gif
Test3.gif (157.93 KiB) Viewed 484 times
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Question] Mouse Over Dockwidget

Post by Kunda1 »

HakanSeven12 wrote: Sat Mar 28, 2020 1:43 pm Result
Nice!
Can something be done about the navicube jumping around ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply