Results 1 to 4 of 4

Thread: Size of component doesn't change when windows change

  1. #1
    Join Date
    Jan 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Size of component doesn't change when windows change

    Hi,
    i did a component that extends to whole size of parent, but it doesn't work when used in a window. If i use it with qmlscene it works but nope on this example. To explain the problem here is my code :

    Fist example with component in separate files

    File : SelectValue2
    Qt Code:
    1. import QtQuick 2.2
    2. import QtQuick.Layouts 1.1
    3. import QtQuick.Controls 1.1
    4.  
    5. Rectangle {
    6. id: rectangle1
    7. property real value : 0
    8. property alias text : texte.text
    9. width: 400
    10. height: 200
    11.  
    12. visible: true
    13.  
    14. Text {
    15. id: texte
    16. text: "o2"
    17. anchors.margins: 5
    18. anchors.left: parent.left
    19. font.pixelSize: 12
    20. width: 30
    21. }
    22.  
    23. TextInput {
    24. id: an
    25. text: value
    26. font.pixelSize: 12
    27. anchors.margins: 5
    28. anchors.rightMargin: 0
    29. anchors.left: texte.right
    30. clip: true
    31. width: 4*font.pixelSize
    32. validator: DoubleValidator {bottom: -10; top: 10; decimals: 2}
    33. Keys.onReturnPressed: value=parseFloat(text)
    34. }
    35.  
    36. Slider {
    37. id: slider
    38. minimumValue: -10
    39. maximumValue: 10
    40. stepSize: 0.1
    41. value: value
    42. anchors.margins: 5
    43. anchors.bottom: parent.bottom
    44. anchors.top: parent.top
    45. anchors.left: an.right
    46. anchors.right: parent.right
    47. onValueChanged: parent.value=value==null?0:Math.floor(value*100)/100
    48. }
    49. onValueChanged: slider.value=value
    50. }
    To copy to clipboard, switch view to plain text mode 

    And the main that use it :
    Qt Code:
    1. import QtQuick 2.2
    2. import QtQuick.Controls 1.1
    3. import QtQuick.Layouts 1.1
    4.  
    5. ApplicationWindow {
    6. id: applicationWindow1
    7. visible: true
    8. width: 640
    9. height: 480
    10. ColumnLayout {
    11. id: grid1
    12. y: 28
    13. anchors.fill: parent
    14. anchors.leftMargin: 5
    15. anchors.rightMargin: 5
    16. onWidthChanged: console.log("Column : "+width)
    17. Text { text: grid1.width
    18. }
    19.  
    20. SelectValue2 {text: "ok"; value: 20; height: 20; width: 800}
    21. SelectValue2 {text: "ok"; value: 20; height: 20; width: grid1.width} // doesn't work why??
    22. SelectValue2 {text: "ok"; value: 20; height: 20}
    23.  
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    Here is the result :
    aeffacer.jpg

    As you can see the size is only made at begining (except for the second one) but after it doesn't change. What is wrong with that code ? If someone can help me please. thanks
    Sincerely

  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: Size of component doesn't change when windows change

    Basically if you put items in a layout then the layout is responsible for positioning them so don't use x, y, width and height properties of such items.
    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. #3
    Join Date
    Jan 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Size of component doesn't change when windows change

    Hi,
    Ok i got it. It works but, not always.
    The code that works :
    File SelectValue3
    Qt Code:
    1. import QtQuick 2.2
    2. import QtQuick.Layouts 1.1
    3. import QtQuick.Controls 1.1
    4.  
    5. Rectangle {
    6. id: rectangle1
    7. property real value : 0
    8. property alias text : texte.text
    9. //width: 400
    10. //height: 200
    11.  
    12. visible: true
    13.  
    14. Text {
    15. id: texte
    16. text: "o2"
    17. anchors.margins: 5
    18. anchors.left: parent.left
    19. anchors.right: an.left
    20. font.pixelSize: 12
    21. width: 30
    22. }
    23.  
    24. TextInput {
    25. id: an
    26. text: value
    27. font.pixelSize: 12
    28. anchors.margins: 5
    29. anchors.rightMargin: 0
    30. anchors.bottom: parent.bottom
    31. anchors.left: texte.right
    32. clip: true
    33. width: 4*font.pixelSize
    34. validator: DoubleValidator {bottom: -10; top: 10; decimals: 2}
    35. Keys.onReturnPressed: value=parseFloat(text)
    36. }
    37.  
    38. Slider {
    39. id: slider
    40. minimumValue: -10
    41. maximumValue: 10
    42. stepSize: 0.1
    43. value: value
    44. anchors.margins: 5
    45. anchors.bottom: parent.bottom
    46. anchors.top: parent.top
    47. anchors.left: an.right
    48. anchors.right: parent.right
    49. onValueChanged: parent.value=value==null?0:Math.floor(value*100)/100
    50. }
    51. onValueChanged: slider.value=value
    52. }
    To copy to clipboard, switch view to plain text mode 

    And the "main"
    Qt Code:
    1. import QtQuick.Controls 1.1
    2. import QtQuick.Layouts 1.1
    3.  
    4. ApplicationWindow {
    5. id: applicationWindow1
    6. visible: true
    7. width: 640
    8. height: 480
    9.  
    10. ColumnLayout {
    11. id: grid1
    12. //y: 28
    13. anchors.fill: parent
    14. anchors.leftMargin: 5
    15. anchors.rightMargin: 5
    16. onWidthChanged: console.log("Column : "+width)
    17. Text { text: grid1.width
    18. }
    19.  
    20. SelectValue3 {text: "ok"; value: 20;
    21. Layout.minimumHeight: 20;
    22. Layout.minimumWidth: 100
    23. Layout.fillWidth: true
    24. }
    25. SelectValue3 {text: "ok"; value: 20;
    26. Layout.minimumHeight: 20;
    27. Layout.minimumWidth: 100
    28. Layout.fillWidth: true
    29. }
    30. SelectValue3 {text: "ok"; value: 20;
    31. Layout.minimumHeight: 20;
    32. Layout.minimumWidth: 100
    33. Layout.fillWidth: true
    34. }
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 

    And now i do a component Anbndelegate, here is the code (file Anbndelegate.qml)
    Qt Code:
    1. import QtQuick 2.2
    2. import QtQuick.Layouts 1.1
    3. import QtQuick.Controls 1.1
    4.  
    5.  
    6. Rectangle {
    7. property int index : 1
    8. property int an : 10
    9. property int bn : 5
    10. //height: index==0?20:40
    11.  
    12. radius: 2
    13. ColumnLayout {
    14. SelectValue3 { value: an; text: "A"+index+" : "; //height: 20;
    15. Layout.fillWidth: true
    16. Layout.minimumHeight: 20;
    17. Layout.minimumWidth: 100
    18. onValueChanged: anbn.set(index,{"an" : value})
    19. onWidthChanged: console.log("SelectValue : "+width)
    20. }
    21. SelectValue3 { value: bn; text: "B"+index+" : "; //height: 20;
    22. visible: index!=0
    23. Layout.fillWidth: true
    24. Layout.minimumHeight: 20;
    25. Layout.minimumWidth: 100
    26. onValueChanged: anbn.set(index,{"bn" : value})
    27. }
    28. }
    29. onWidthChanged: console.log("Delegate Width changed "+parent.width)
    30. }
    To copy to clipboard, switch view to plain text mode 

    And i try to use it
    Qt Code:
    1. import QtQuick 2.2
    2. import QtQuick.Controls 1.1
    3. import QtQuick.Layouts 1.1
    4.  
    5. ApplicationWindow {
    6. id: applicationWindow1
    7. visible: true
    8. width: 640
    9. height: 480
    10. Anbndelegate {
    11. anchors.fill: parent
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    But it doesn't work. Size doesn't change. Sorry for all that questions i'm new at QtQuick.
    Thanks
    Last edited by archqt; 17th June 2014 at 17:11.

  4. #4
    Join Date
    Jan 2011
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Size of component doesn't change when windows change

    Hi,
    it works i just forgot anchors.fillarent to make the LayoutColumn take the whole parent size.

Similar Threads

  1. change text size and window size - qmessagebox
    By smemamian in forum Newbie
    Replies: 3
    Last Post: 4th July 2013, 07:38
  2. ListWidget doesn't change size with containing QGroupBox.
    By davethomaspilot in forum Qt Programming
    Replies: 5
    Last Post: 30th January 2013, 23:57
  3. Replies: 1
    Last Post: 23rd November 2011, 04:41
  4. Replies: 2
    Last Post: 21st May 2007, 21:12
  5. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16

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.