Results 1 to 5 of 5

Thread: Best way to calculate fixed width for QwtScaleWidget?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Best way to calculate fixed width for QwtScaleWidget?

    Check the plotmatrix example.

    Uwe

  2. #2
    Join Date
    Jan 2014
    Posts
    36
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Best way to calculate fixed width for QwtScaleWidget?

    Check the plotmatrix example
    Are you referring to the function PlotMatrix::alignVAxes(), where you're looping through the rows and setting the minimum extent of the scale draw widgets? If so, that's not exactly the case I'm describing. Or maybe I'm just misunderstanding your hint? In your example, you're setting the minimum extent of all scale widgets to what it needs to be for the widest scale widget based on the current values set on each plot's scale widget. So there's two issues with that for what I need. First, since you're only setting minimum extent, there's nothing that prevents the widget from grow wider as the scale changes to require extra digit(s). I'm guessing the fix for that is call setFixedWidth(maxExtent) instead of setMinimumExtent(maxExtent). But that leads to the second problem, which I think is my real issue, you're only calculating maxExtent based on the current values, not the potential value that could happen later.

    For example, say I have a simple setup where I only have two vertically aligned plots. The first plot is starts scaled from 0 to 1. The second plot is starts scaled from 0 to 10. However, I know that the user could choose to add a data curve that needs to be scaled from 0 to 10000. What I need to do is set a fixed width based on a value that isn't necessarily set on any of the scale widgets yet. So from the time my application launches, I want to set the width of all the scale widgets to be large enough to hold 10000 without the scale widget ever needing a resize, the only time I'd ever need to resize the scale widgets is if the user changed the application font.

    So in my above example, calling QwtScaleDraw::extent(QFont) on either of the two existing plots won't give me the correct answer, since it would only return the size needed to show a "1" or a "10", not the size needed to show a "10000".

    Or are you suggesting that when my application launches, I should immediately create a plot, set the scale to 10000, call extent() at that point, call setFixedWidth() with that value, and then return the plot to the default scale? I'm a little worried that might cause a flicker, but I could try it.

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Best way to calculate fixed width for QwtScaleWidget?

    If the width is calculated from another scale or some maximum related to f.e QFontMetrics::width( "100000.000" ) - in the end it is always about setting QwtScaleDraw::setMinimumExtent().

    Uwe

  4. #4
    Join Date
    Jan 2014
    Posts
    36
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Best way to calculate fixed width for QwtScaleWidget?

    Ok, I get that you're saying the right function to call is QwtScaleDraw::setMinimumExtent(double minExtent).

    I'm still unsure how to calculate the correct value for minExtent to pass to that function? My understanding is the value I want to pass in for minExtent is the width (in pixels) of my text string, plus the width of the tick marks, plus some more pixels for spacing/margins. So font metrics alone isn't enough to give me the extent I need. So I'm just unsure of how to take into account all the scale widget component widths to arrive at the appropriate value.

Similar Threads

  1. QListWidget width always fixed to 256
    By Suppaman in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2013, 23:19
  2. Replies: 3
    Last Post: 11th July 2012, 07:56
  3. Fixed column width in QAbstractTableModel
    By hailflex in forum Newbie
    Replies: 1
    Last Post: 11th December 2009, 07:58
  4. QToolBox width fixed to maximum content width
    By ghorwin in forum Qt Programming
    Replies: 0
    Last Post: 10th July 2009, 10:58
  5. QWidget with fixed width height ratio
    By Lodorot in forum Qt Programming
    Replies: 1
    Last Post: 26th May 2009, 09:49

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
  •  
Qt is a trademark of The Qt Company.