Unwanted Value Changes in Custom Widgets

A forum for research and development of the user interface of FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Unwanted Value Changes in Custom Widgets

Post by wandererfan »

When I use the mouse wheel to scroll, any of the FC custom widgets that are touched by the cursor in passing increment or decrement their value. Don't think I've ever run into this in other applications.

Does anybody else notice this behaviour?

To me, the scroll wheel should only affect a widget's value if that widget already has focus via click or tab.

Thoughts?
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Unwanted Value Changes in Custom Widgets

Post by Kunda1 »

wandererfan wrote: Mon Jan 27, 2020 1:55 pm Does anybody else notice this behaviour?

To me, the scroll wheel should only affect a widget's value if that widget already has focus via click or tab.

Thoughts?
This is a super common phenomena in Scribus as well which uses Qt.
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
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Unwanted Value Changes in Custom Widgets

Post by openBrain »

It has pros (you can change a value without having to click on it first) and cons (you sometimes change value inadvertently). :)

I don't know if it's enough, but we could change focus policy of the spin boxes with :

Code: Select all

spinbox->setFocusPolicy(Qt::StrongFocus) #Default is Qt::WheelFocus which also accepts focus at wheel event
At least we could test with some Python to see if it works. ;)
chrisb
Veteran
Posts: 54150
Joined: Tue Mar 17, 2015 9:14 am

Re: Unwanted Value Changes in Custom Widgets

Post by chrisb »

I would appreciate the extra click. Working on a notebok I have a) always a small screen and b) often no mouse attached. Thus I frequently have to scroll the DataTab, and if the mouse is not in the left part of the widget then some values may be changed inadvertently.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Unwanted Value Changes in Custom Widgets

Post by wandererfan »

openBrain wrote: Mon Jan 27, 2020 2:34 pm I don't know if it's enough, but we could change focus policy of the spin boxes with :

Code: Select all

spinbox->setFocusPolicy(Qt::StrongFocus) #Default is Qt::WheelFocus which also accepts focus at wheel event
I tried this in "InputField.cpp" and it didn't help. What did help was changing the "wheelEvent" handler to not accept events if the input field didn't already have focus.

Have to check the other custom widgets and see if the same tweak works.
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Unwanted Value Changes in Custom Widgets

Post by wandererfan »

chrisb wrote: Mon Jan 27, 2020 9:45 pm I would appreciate the extra click. Working on a notebok I have a) always a small screen and b) often no mouse attached. Thus I frequently have to scroll the DataTab, and if the mouse is not in the left part of the widget then some values may be changed inadvertently.
This is my situation as well.
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Unwanted Value Changes in Custom Widgets

Post by wandererfan »

Here is an illustration of the current situation vs "how it should be". Excuse the video quality.

In the Preset widget you can clearly see values changes during scrolling using the current code. With proposed code the Preset widget is quite resistant to undesired changes.
Attachments
ArchWindowNew.gif
ArchWindowNew.gif (318.13 KiB) Viewed 689 times
ArchWindowCurrent.gif
ArchWindowCurrent.gif (234.48 KiB) Viewed 689 times
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Unwanted Value Changes in Custom Widgets

Post by wandererfan »

And here is a little write up of the proposed changes. Not that individual maintainer will have to decide if they want to use the new options or not.

-------------------------------------------------------------------------------

Proposed solution for preventing uncommanded value changes on scroll or
mouse wheel.

Fields treated with the following options require Tab or Click to receive focus,
and will not change values until they have focus. Once they have focus, the mouse
wheel can scroll the values up and down.

The behaviour of fields not treated with these option will be unchanged.

Usage of new options:

Code: Select all

C++
#include <Gui/Widgets.h>

    //regular Qt widgets
    //sbScale is a QDoubleSpin box
    ui->sbScale->installEventFilter(new Gui::WheelFilter(ui->sbScale));

    //FC custom widgets
    //ifInput is Gui::InputField
    ui->ifInput->setWheelBlocker(true)

Python
# FreeCADGui.InputField
    inField = ui.createWidget("Gui::InputField")
    inField.setProperty("wheelBlocker", True)

# regular Qt Widgets
    inCombo = QtGui.QComboBox()
    WheelFilter(inCombo)    #*** the WheelFilter class needs a home from which
                            #*** it can be imported or it can just be copy/pasted.
                            #*** It is < 20 lines of code, but it would be best 
                            #*** from a maintenance perspective if the code was
                            #*** only in 1 place. 
Post Reply