Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:07:15+00:00 2026-06-13T20:07:15+00:00

I have a USB device that can move along a linear axis, stop at

  • 0

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:

enter image description here

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:07:17+00:00Added an answer on June 13, 2026 at 8:07 pm

    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 implementation

    QWidget::mouseMoveEvent — first check if clickedOnIndicator is true or not; if so, move the indicator to the new position and emit a signal YourWidget::indicatorMoved(int), otherwise call the default implementation

    QWidget::paintEvent — paint the indicator at the correct position (and do whatever else you were doing in the paint event)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .sh script that automounts any usb device that is plugged in.
I have a Linux USB HID device (a Hama MCE ), and I can
I have a USB device that I need to be able to talk to
Background information: I presently have a hardware device that connects to the USB port.
I have a USB GSM device which I use for Internet connection as well
I have to simulate a USB Device for automation and testing purposes (in Linux).
I have enabled USB debugging on my phone and have set the Debuggable permission
I have a USB device I'm trying to communicate with over a virtual serial
I'm implementing a class that talks to a motor controller over a USB device.
Couple of quick questions. I have a DMX king USB lighting controller that I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.