Results 1 to 6 of 6

Thread: Shrinking CircularGauge Area to Displayed Range?

  1. #1
    Join Date
    Dec 2011
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Shrinking CircularGauge Area to Displayed Range?

    Hi all,

    When creating a CircularGauge, the CircularGauge element always consumes the total area as if the entire circle of the gauge were displayed, even if the minimumValue angle and maximumValueAngle combinations result in a half-circle or less.

    Is there a way to force the CircularGauge element to take no more vertical room than required to display the visible portion of the gauge?

    See, for example, the following image and code -- the desired outcome is that the black box stops at the bottom of the visible portion of the gauge, not where a full-circle gauge would have gone.

    Thanks in advance for any advice!

    gauge.png

    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Window 2.2
    3. import QtQuick.Controls 1.4
    4. import QtQuick.Controls.Styles 1.4
    5. import QtQuick.Extras 1.4
    6. import QtQuick.Layouts 1.1
    7. import QtQuick.Extras.Private 1.0
    8.  
    9. Window {
    10. visible: true
    11. width: 640
    12. height: 480
    13. title: qsTr("Hello World")
    14.  
    15. MainForm {
    16. anchors.fill: parent
    17.  
    18.  
    19. Column {
    20.  
    21. spacing: 2
    22.  
    23.  
    24. Rectangle {
    25. width: 400
    26. height: 200
    27. color: "#000000"
    28.  
    29. CircularGauge {
    30.  
    31. width: 400
    32. height: 200
    33.  
    34. style: CircularGaugeStyle {
    35. maximumValueAngle: 90
    36. minimumValueAngle: -90
    37.  
    38.  
    39. }
    40. }
    41. }
    42.  
    43.  
    44. Rectangle {
    45.  
    46. color: "#ccffcc"
    47. border.color: "black"
    48.  
    49. height: 75
    50. width: 50
    51.  
    52. }
    53. }
    54. }
    55. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Shrinking CircularGauge Area to Displayed Range?

    The black box and the gauge have fixed sizes in your example, so that's how big they wil appear.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2011
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Shrinking CircularGauge Area to Displayed Range?

    Having tried every possible combination of fixed and dynamic sizing of CircularGauge elements that I can think of, I have every single time been displayed an element that has 2x the height necessary to display the half-circle form of the gauge. Can you provide an example where the gauge's element would *not* be 2x the height of a half-circle gauge?

    Or, to state another way - is there any way of having a half-circle CircularGauge filling the entire height of its element, rather than only half of the height.

    See, for the following example, no size is specified, and yet the container ends up 2x the height of the half-circle gauge:

    Qt Code:
    1. Window {
    2. visible: true
    3. width: 640
    4. height: 480
    5. title: qsTr("Hello World")
    6.  
    7. MainForm {
    8. anchors.fill: parent
    9.  
    10.  
    11. GridLayout {
    12.  
    13. id: gridlayout
    14.  
    15. columns: 1
    16. rows: 2
    17. anchors.fill: parent
    18. Layout.margins: 0
    19.  
    20. Rectangle {
    21.  
    22. color: "#000000"
    23. CircularGauge {
    24.  
    25. style: CircularGaugeStyle {
    26. maximumValueAngle: 90
    27. minimumValueAngle: -90
    28.  
    29.  
    30. }
    31. }
    32. }
    33.  
    34.  
    35. Rectangle {
    36.  
    37. color: "#ccffcc"
    38. border.color: "black"
    39.  
    40. height: 50
    41. width: 100
    42. }
    43. }
    44. }
    45. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by droneone; 28th August 2016 at 15:10.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Shrinking CircularGauge Area to Displayed Range?

    A Rectangle without any size is usually not visible, but the GridLayout might set at least a width here.

    If you make the Rectangle half the height of the gauge, it should end where you want it to end.

    Cheers,
    _

  5. #5
    Join Date
    Dec 2011
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Shrinking CircularGauge Area to Displayed Range?

    Quote Originally Posted by anda_skoa View Post
    A Rectangle without any size is usually not visible, but the GridLayout might set at least a width here.

    If you make the Rectangle half the height of the gauge, it should end where you want it to end.

    Cheers,
    _
    ... the problem is that at that point, the vertical height of the half-circle gauge is cut in half, leaving again, 50% of the element blank when drawing a half-circle gauge, no matter how small you make the element.

    It turns out there's a very ugly, fairly hackish solution, which is to increase the scale of the circular gauge, and then offset it such that the center is where the bottom would be. You will need to ensure that clipping is on and that there is enough space between elements that the foreground of the gauge is not covered up. See:

    gauge2.jpg

    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Window 2.2
    3. import QtQuick.Controls 1.4
    4. import QtQuick.Controls.Styles 1.4
    5. import QtQuick.Extras 1.4
    6. import QtQuick.Layouts 1.1
    7. import QtQuick.Extras.Private 1.0
    8.  
    9. Window {
    10. visible: true
    11. width: 800
    12. height: 480
    13. title: qsTr("Hello World")
    14.  
    15. MainForm {
    16. anchors.fill: parent
    17.  
    18. Column {
    19. spacing: 20
    20.  
    21. Rectangle {
    22. width: 800
    23. height: 200
    24. color: "#000000"
    25.  
    26. CircularGauge {
    27. width: 800
    28. height: 200
    29. scale: 1.9
    30. anchors.verticalCenter: parent.bottom
    31. antialiasing: true
    32.  
    33. style: CircularGaugeStyle {
    34. maximumValueAngle: 90
    35. minimumValueAngle: -90
    36.  
    37. background: Rectangle {
    38. color: "white"
    39. }
    40. }
    41. }
    42. }
    43.  
    44. Rectangle {
    45. color: "#ccffcc"
    46. border.color: "black"
    47. height: 75
    48. width: 500
    49. }
    50. }
    51. }
    52. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Shrinking CircularGauge Area to Displayed Range?

    Quote Originally Posted by droneone View Post
    ... the problem is that at that point, the vertical height of the half-circle gauge is cut in half, leaving again, 50% of the element blank when drawing a half-circle gauge, no matter how small you make the element.
    Since there is nothing drawn in the lower half, it doesn't matter.
    You seem to have changed the gauge to draw a background, so you jsut need to enable clipping on the properly sized parent.

    Qt Code:
    1. Rectangle {
    2. width: gauge.width
    3. height: gauge.height / 2
    4. clip: true
    5. color: "black"
    6.  
    7. Rectangle { // using rectangle here instead of the gauge to simulate a circle
    8. id: gauge
    9. width: 400
    10. height: width
    11. radius: width / 2
    12. color: "red"
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    This only shows the upper half of the inner rectangle, basically showing a half circle.

    Cheers,
    _

Similar Threads

  1. Prevent QMenuBar in QMainWindow from shrinking
    By Radagast in forum Qt Programming
    Replies: 0
    Last Post: 3rd March 2015, 15:02
  2. How to change the scroll area range in QTableView?
    By josentop in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2012, 14:13
  3. Expanding/shrinking a widget
    By punkypogo in forum Qt Programming
    Replies: 6
    Last Post: 27th May 2008, 16:50
  4. Shrinking connection dialog
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 23rd April 2008, 19:59
  5. expanding/shrinking issues.
    By Preeteesh in forum Qt Programming
    Replies: 5
    Last Post: 16th June 2007, 21:27

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.