Okay, advice taken. I will try to do it without globals now.
I started to use them when I had trouble to access my main widget (QTest) in a little test project I made with Qt Creator. It uses a custom widget class for drawing that does not know about my main class.
Now I added a member variable containing a pointer to my main widget, and set it like this in the constructor:
m_QTest = (QTest*) parent->parent();
What I did not like about this is that when I move that widget deeper in the hierarchy, I have to change this. So the widget needs to know where it is, and cannot be treated as a black box like before.
Hmm, that does seem to toggle whether I get events while dragging as slider, or only after it has been moved. My problem is another one:Have a look at the 'tracking' property.
I have a slider and a text input field, both are methods to specify the radius of the object I draw. There is also an update button to force a redraw. So, I made connections from the slider and the text input field to the update button, and now my object gets redrawn when I press the update button, move the slider or edit the text input field. But how do I make sure the slider and the input field always show the same value? I could set their values in the onUpdateButton_clicked() event, but this would generate additional events:
- change value in input field
- m_radius gets set in on_radiusLineEdit_textChanged()
- signal is sent to onUpdateButton_clicked(), which updates the draw area, and sets the values of the text input field (unnecessary, but not harmful) and the slider
- this generates an event for the slider that has changed
- things are drawn again, and the value in the text field is changed a little, because the slider has a resolution of 1-100, while the input field's value is donverted into a a floating point with more precision
- and again the changed text field will generate an event
How do I avoid this? Simply disable event processing somehow, update the values in all widgets, and enable events again? I am probably overlooking something simple here.





Reply With Quote

Bookmarks