Results 1 to 5 of 5

Thread: Align QwtSlider and QwtPlot

  1. #1
    Join Date
    May 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Align QwtSlider and QwtPlot

    Hi everyone,

    I am writing a control system simulation. A QwtSlider (the right one in the picture) is used to indicate a desired value while the left one follows its position using control system theory. Now I would like to have the QwtPlot draw the curve that the slider makes - basically use the slider as a seismometer needle. This works pretty well as you can see, but I still have one problem: I would like to align the slider and the plot so that the scales are the same. As you can see on the picture the Slider and the Plot both show the same value but there is a significal offset due to different sizes of the scales on the screen. Now I'm looking for a way to align the slider and the plot to have scales of exactly same size and same vertical origin so that they represent their values at the same vertical coordinates on the screen. Here's the pic:

  2. #2
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Align QwtSlider and QwtPlot

    Why don't you match the size of sliders to the size of axis Y?

  3. #3
    Join Date
    May 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Align QwtSlider and QwtPlot

    Tried this by using ui.qwtPlot->axisWidget(QwtPlot::yLeft)->height() but it returned some weird results. To be honest there are so many possibilities to affect the visual appearance of qwt widgets that I do not know where to start looking for a solution.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Align QwtSlider and QwtPlot

    Of course you have to implement the layout code manually instead of using a QLayout by reimplementing the resizeEvent of the container widget ( parent of plot and slider ).

    The scale and the geometry of the slider also needs be adjusted whenever the plot axis scale changes ( QwtScaleWidget::scaleDivChanged() ) and the geometry of this scale widget changes ( use an event filter and check its move and resize events ).

    And finally you have to align your slider geometry taking QwtScaleWidget::startBorderDist() and QwtScaleWidget::endBorderDist() into count subtracting them from the border hints of the slider scale.

    This all needs a deep understanding of the QwtPlot layout system and some sort of know how about Qt. Start with trying to understand what QwtScaleDraw::getBorderDistHint() is about.

    Uwe

  5. #5
    Join Date
    May 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Align QwtSlider and QwtPlot

    Thank you for the replies.

    Reimplementing at low layouting level is something I will surely stay away from in this case as the amount of work I would have to put into this is simply not worth it (this is a project I do in my spare time, nothing work-related so I can live with that offset rather than spending hours with a task not directly related with my project). Thank you for the guide though.

    In a quick test I removed the bottom scale of the plot and the scales were aligned well. I guess I might as well enlarge one of the scales by a certain offset, let's say have the scale on the plot go from -1000..1000 and the one on the slider work from -(1000+x)...1000 so that they still are aligned in the relevant area. The code should be a lot more simple than a complete rework of the layouting and painting functions.

Similar Threads

  1. Setting Initial QwtSlider Position
    By Mannion in forum Qwt
    Replies: 4
    Last Post: 3rd May 2011, 21:24
  2. QTextEdit align
    By mero in forum Qt Programming
    Replies: 5
    Last Post: 29th March 2011, 08:10
  3. Question about align
    By Archa4 in forum Newbie
    Replies: 4
    Last Post: 14th March 2011, 08:36
  4. Replies: 6
    Last Post: 14th May 2009, 12:02
  5. QItemDelegate Align
    By aekilic in forum Qt Programming
    Replies: 43
    Last Post: 1st April 2009, 07:52

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.