I have a USB device that can
- “move” along a linear axis,
- stop at a target,
- report its position,
- report its target,
- have its target set by the host application.
Now I want to create a widget that I can use to indicate position and target, but I also want the target indicator to be draggable with the mouse. What I have accomplished so far is the indicating part, which looks like this:

The black, filled triangle is the position; the target indicator is green.
What I want is to be able drag the target indicator around. While this is being done, the device’s target should be updated with the current target indicator’s value. I’m new to gui programming (until now I only took care of the USB stuff; this is my first custom widget), and I’m not sure how I can accomplish this.
Is it a good idea to leave the target indicator as a part of the widget, or should it be some kind of child? I’m pretty sure there are common patterns for this kind of job, but I don’t know the right keywords to find them. Googling for things like “QWidget drag” only leads me to the drag and drop functions, which is not quite what I need.
I don’t think you should bother with child widgets. In your main QWidget, you just need to override three virtual protected functions:
QWidget::mousePressEvent— this should check whether or not the user clicked on the target indicator, and if so, set a bool “clickedOnIndicator” to true (and accept the mouse event); otherwise set the bool to false, ignore the mouse event, and call the default implementationQWidget::mouseMoveEvent— first check ifclickedOnIndicatoris true or not; if so, move the indicator to the new position and emit a signalYourWidget::indicatorMoved(int), otherwise call the default implementationQWidget::paintEvent— paint the indicator at the correct position (and do whatever else you were doing in the paint event)