Results 1 to 2 of 2

Thread: Height/Width of Qt Quick Controls

  1. #1
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Height/Width of Qt Quick Controls

    Hi,

    I am developing an app using Qt5.7/Qt Quick controls.

    I want to setup height/width for the QtQuicks controls like Textfiled/Button/Rectangle using QML.
    I want to setup the height/width of the controls which adjust according to screen size/orientation of the target devices.
    Now, I am providing the Pixel value which turn out a mess when the same app deployed in Tablets/smartphones.
    Last edited by Mathan; 26th August 2016 at 14:19.

  2. #2
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Height/Width of Qt Quick Controls

    I went with creating JavaScript functions that allow for me to specify % sizes, physical sizes, etc...:

    Qt Code:
    1. //returns a density ratio of the current screen
    2. function appDensityRatio () {
    3. return appWin.appDensity / 11.6129; //appWin references the main window, and appDensity is set to Screen.pixelDensity
    4. }
    5.  
    6. // returns the pixels that equate to the provided inches
    7. function inchHeight(myInches){
    8. if( appDensityRatio() < 1.0 ) {
    9. if( appDensityRatio() >= 0.70 ) {
    10. return Math.round(myInches*(appWin.appDensity*25.4*appDensityRatio()));
    11. } else {
    12. return Math.round(myInches*(appWin.appDensity*25.4*0.70));
    13. }
    14. } else {
    15. return Math.round(myInches*(appWin.appDensity*25.4));
    16. }
    17. }
    18.  
    19. //returns a size as a percentage of the given size
    20. function psize(pcent,fullval){
    21. return pcent*(fullval/100)
    22. }
    23.  
    24. // returns the pixels that equate to the provided point size
    25. function pointHeight(myPoints){
    26. if( appDensityRatio() < 1.0 ) {
    27. if( appDensityRatio() >= 0.70 ) {
    28. return Math.round(myPoints*Math.round(appDensityRatio()*(appWin.appDensity*25.4)/72.0));
    29. } else {
    30. return Math.round(myPoints*Math.round(0.70*(appWin.appDensity*25.4)/72.0));
    31. }
    32. } else {
    33. return Math.round(myPoints*Math.round((appWin.appDensity*25.4)/72.0));
    34. }
    35. }
    36.  
    37. // returns the pixels that equate to the provided point size, used for FONTS only
    38. function fontHeight(myPoints){
    39. if( Math.round(appWin.appPixelRatio*fHeight()) < 1280 ) {
    40. return Math.round(myPoints * 0.75);
    41. } else {
    42. return myPoints;
    43. }
    44. }
    To copy to clipboard, switch view to plain text mode 

    Then I can set a size on the base window... and size everything on that size...
    Qt Code:
    1. ApplicationWindow {
    2. id: main_window
    3. objectName: "main_window"
    4. x:0
    5. y:0
    6. width: Screen.width
    7. height: Screen.height
    8. }
    To copy to clipboard, switch view to plain text mode 

    Child windows are sized with
    Qt Code:
    1. anchors.fill: parent
    To copy to clipboard, switch view to plain text mode 
    and all child window objects are sized to their parent with calls like so:
    Qt Code:
    1. Rectangle { //Child Window (included in Main using a StackView)
    2. id: graphWindow
    3. border.color: "red"
    4. border.width: 2
    5. radius: 10
    6.  
    7. Rectangle { //Child object
    8. id: wspdChartRect
    9. color: appWin.rectBackColor
    10. anchors.left: parent.left
    11. anchors.leftMargin: Funcs.psize(1,graphWindow.width)
    12. anchors.right: parent.right
    13. anchors.rightMargin: Funcs.psize(1,graphWindow.width)
    14. anchors.top: parent.top
    15. anchors.topMargin: Funcs.psize(1,graphWindow.height)
    16. height: Funcs.psize(48,graphWindow.height)
    17. width: Funcs.psize(98,graphWindow.width)
    18. border.color: "red"
    19. border.width: 2
    20. radius: 10
    21. visible: true
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. how to get image height and width in qt
    By iswaryasenthilkumar in forum Newbie
    Replies: 1
    Last Post: 31st March 2015, 06:52
  2. Pusbutton height and width
    By seany in forum Qt Programming
    Replies: 6
    Last Post: 7th June 2013, 06:35
  3. Widget Height and Width
    By in_dbasu in forum Qt Programming
    Replies: 3
    Last Post: 11th August 2011, 08:44
  4. QLayout: different SizeConstraints for width and height?
    By PhilippB in forum Qt Programming
    Replies: 0
    Last Post: 23rd February 2009, 16:33
  5. width and height of QTabWidget
    By chikkireddi in forum Qt Programming
    Replies: 6
    Last Post: 29th October 2007, 13:53

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.