Results 1 to 3 of 3

Thread: custom widget that contains moving parts

  1. #1
    Join Date
    Oct 2011
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default custom widget that contains moving parts

    Hi,

    I was wondering what the best approach for creating a custom widget that contains moving parts is. Say I was going to create something from scratch like a slider widget similar to QSlider, for example, then the handle of the slider obviously must be able to be dragged. If this widget was designed in QtDesigner then, unless I'm mistaken, in order for the handle to be promoted to be able to receive direct mouse events in a custom class, the handle itself must be in one of the structured layouts which defeats its purpose of it being movable. I experimented by placing some widgets inside a parent widget without any structured layouts applied and promoted a couple of the child widgets but they do not show when the code is run.

    So what would be the best approach/structure of designing something along these lines?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: custom widget that contains moving parts

    If we stick to the slider example, I would subclass a plain widget and add a custom paint event. Inside the paint event draw all yourself. Reimp mouse***event and do the calculation if the slider (= the position) was pressed or not etc. Then call update(QRect) to force a paint update.

    So no moving widget at all. Catch the mouse events, calculate what should change (position of the slider), store the results in member variable, call paint, and paint the appearance according to the member variables.

  3. The following user says thank you to Lykurg for this useful post:

    cgyan1 (14th February 2012)

  4. #3
    Join Date
    Oct 2011
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: custom widget that contains moving parts

    Yes, that's a nice idea and will probably work very well for what I have in mind and will also work well for other ideas I have.
    Thanks very much!

Similar Threads

  1. mouseMoveEvent: KDE moving widget
    By NullPointer in forum Newbie
    Replies: 1
    Last Post: 17th August 2011, 15:57
  2. Replies: 1
    Last Post: 24th June 2011, 00:09
  3. Qt Designer Problem moving widget after breaking layout
    By nickolais in forum Qt Tools
    Replies: 0
    Last Post: 10th June 2010, 23:21
  4. Replies: 1
    Last Post: 6th November 2006, 00:50
  5. [Qt4] - Moving Widget...
    By IPFreely in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2006, 10:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.