Results 1 to 5 of 5

Thread: Spacers

  1. #1
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Spacers

    Hi
    Is there any built-in spacer in qml, so that I don't have to hardcode pixel heights/widths (what gives me flexibility among devices)?
    Thanks in advance
    Last edited by marmistrz; 13th July 2012 at 17:47.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Spacers

    Use anchors to attach one element to another so that you don't need spacers. There is rarely need for something different but if you present your exact situation, maybe we can find a solution that fits.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    marmistrz (15th July 2012)

  4. #3
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Spacers

    Quote Originally Posted by wysota View Post
    Use anchors to attach one element to another so that you don't need spacers. There is rarely need for something different but if you present your exact situation, maybe we can find a solution that fits.
    Thanks for your reply
    It's an app for mobile device. The height will be sometimes 480 px (landscape), sometimes 800 px (portrait N900), sometimes 854 px (portrait N9), maybe sometimes something else (when I decide to release it for other devices)

    main.qml
    Qt Code:
    1. import QtQuick 1.0
    2. import com.nokia.meego 1.0
    3. //property color fontcolor: "white"
    4.  
    5. PageStackWindow
    6. {
    7. id: pagestackwindow
    8. property int screenwidth: (screen.currentOrientation == Screen.Landscape) ? screen.displayWidth : screen.displayHeight // to ensure
    9.  
    10. visible: true
    11. MainPage
    12. {
    13. id: mainview
    14. }
    15. initialPage: mainview
    16. ToolBarLayout
    17. {
    18. id: toolbar
    19. ToolIcon
    20. {
    21. iconId: "toolbar-back"
    22. onClicked: pageStack.pop()
    23. }
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    MainPage.qml
    Qt Code:
    1. import QtQuick 1.0
    2. import com.nokia.meego 1.0
    3.  
    4. Page
    5. {
    6. id: mainPage
    7. tools: toolbar
    8. Column
    9. {
    10. width: parent.width
    11. CheckBox
    12. {
    13. id: tracksrc
    14. text: "Select track from library" // label isn't needed with PageStackWindow
    15. checked: true
    16. anchors.horizontalCenter: parent.horizontalCenter
    17. //checkable: true
    18. }
    19.  
    20. // button for selecting a track from the media library
    21. Button
    22. {
    23. id: selecttrack
    24. text: "No track selected"
    25. checkable: false
    26. visible: tracksrc.checked
    27. width: screenwidth
    28. onClicked:
    29. {
    30. console.log("Select track button clicked")
    31. pageStack.push(Qt.resolvedUrl("SelectTrackPage.qml"))
    32. }
    33. }
    34.  
    35. //line edits for entering the data manually
    36.  
    37. TextField
    38. {
    39. id: artistfield
    40. placeholderText: "Artist"
    41. visible: !tracksrc.checked
    42. width: screenwidth
    43. }
    44. TextField
    45. {
    46. id: trackfield
    47. placeholderText: "Track"
    48. visible: !tracksrc.checked
    49. width: screenwidth
    50. }
    51.  
    52. Button
    53. {
    54. id: lyricssrcbutton
    55. text: lyricssrcdialog.model.get(lyricssrcdialog.selectedIndex).name
    56. width: screenwidth
    57. onClicked: { lyricssrcdialog.open(); }
    58. }
    59.  
    60. Button
    61. {
    62. id: go
    63. text: "Go!"
    64. width: screenwidth
    65. onClicked:
    66. {
    67. console.log("Go! button clicked")
    68. pageStack.push(Qt.resolvedUrl("ShowLyricsPage.qml"))
    69. }
    70. }
    71. }
    72. SelectionDialog
    73. {
    74. id: lyricssrcdialog
    75. titleText: "Download source"
    76. selectedIndex: 0
    77. model: ListModel
    78. {
    79. ListElement { name: "AZLyrics" }
    80. }
    81. }
    82. OKDialog
    83. {
    84. id: notimplementeddialog
    85. message: "Sorry, not implemented yet!"
    86. }
    87. }
    To copy to clipboard, switch view to plain text mode 

    There are other pages, but I don't think they'll be relevant now.

    I'm using the built-in qml application viewer

    When created this way there's only one block of components and I'd like to place them among all the screen.
    Attached Images Attached Images

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Spacers

    This is one possibility:

    javascript Code:
    1. import QtQuick 1.1
    2.  
    3. Item {
    4. Rectangle {
    5. id: i1
    6. color: "#ccc"
    7. anchors.top: parent.top
    8. anchors.left: parent.left
    9. anchors.right: parent.right
    10. height: parent.height/3
    11.  
    12. Rectangle {
    13. id: b1
    14. anchors.centerIn: parent
    15. color: "blue"
    16. Text { text: "B1"; anchors.centerIn: parent; color: "white" }
    17. width: 200
    18. height: 50
    19. }
    20. }
    21. Rectangle {
    22. id: i2
    23. color: "#777"
    24. anchors.top: i1.bottom
    25. anchors.left: parent.left
    26. anchors.right: parent.right
    27. height: i1.height
    28. Rectangle {
    29. id: b2
    30. anchors.centerIn: parent
    31. color: "blue"
    32. Text { text: "B2"; anchors.centerIn: parent; color: "white" }
    33. width: 200
    34. height: 50
    35. }
    36. }
    37. Rectangle {
    38. id: i3
    39. color: "#aaa"
    40. anchors.top: i2.bottom
    41. anchors.bottom: parent.bottom
    42. anchors.left: parent.left
    43. anchors.right: parent.right
    44. height: i1.height
    45. Rectangle {
    46. id: b3
    47. anchors.centerIn: parent
    48. color: "blue"
    49. Text { text: "B3"; anchors.centerIn: parent; color: "white" }
    50. width: 200
    51. height: 50
    52. }
    53. }
    54. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    marmistrz (15th July 2012)

  7. #5
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Spacers

    Thanks.
    Using your idea I can place Rectanges inside Column and have width: parent.width and height: parent.height/x, x is the number of sections.
    (using horizontalCenter if needed instead of centerIn)

Similar Threads

  1. Question about the "spacers"
    By Cantora in forum Newbie
    Replies: 3
    Last Post: 2nd April 2009, 08:45

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.