1

I create a Setting class and set an instance of it as a context property in root context. In qml file I called value to read settings values.

All settings are working correctly except width and height. They're properly load but not applied. here is an example of it:

import QtQuick 2.0

Item{
    id: diagram_main
    property string url

    height: settings.value(url + "/height")
    width: settings.value(url + "/width")
    visible: settings.value(url + "/visible")

    Text {
        id: diagram_label
        property string url: diagram_main.url + "/label"
        text: settings.value(url)
        color: settings.value(url + "PenColor")
        font.family: settings.value(url + "PenName")
        font.pointSize: settings.value(url + "PenSize")
    }
}

here visible and text and it's color and font settings are working correctly but not width or height.

hamed1soleimani
  • 304
  • 1
  • 2
  • 13
  • 1
    Note that `Item` (parent of your `Text` element) would not affect width/height of your `Text` element. Your `Text` element would expand it's size to simply fit all of the actual text. – rsht May 04 '16 at 12:06
  • 1
    I don't really know what behavior you want to achieve, but I guess that you want your `Text` element to have the same size as it's parent. In this case simply add `anchors.fill: parent` in your `Text` element. Also, if you want to see what actual values are used for width/height you can add something like `Component.onCompleted: console.log(settings.value(url + "/height"), settings.value(url + "/width"))` . For real QML debugging google *Debugging Qt Quick Projects* – rsht May 04 '16 at 12:12
  • @Roman here is a screen shot of it : http://postimg.org/image/nkf1d389t/ i expect main window to resize with changing height and width. but it dosent resize and remain at it's deafult size. I'm changing text size with it's font.pointsize – hamed1soleimani May 04 '16 at 12:17
  • In this case you should set your root element's width/height to be dependent to your Text's ones. Look at this simple example: http://pastebin.com/gaQ14sqi . Note, that setting width/height of the parent to be dependent on it's childrens' is considered a bad practice – rsht May 04 '16 at 12:35
  • @Roman the text was for testing other settings. It's not relates to text. I want to resize my main window with height/width settings. about 10 other components will be in this window and they size and place will be set with margins ant their own x,y,w,h! – hamed1soleimani May 04 '16 at 12:41
  • Ok, got you. Than it looks like your settings' values aren't being delivered to width/height properties correctly. Try to place `Component.onCompleted: console.log(settings.value(url + "/height"), settings.value(url + "/width"))` and see what the result. Also, are there any errors on console output? – rsht May 04 '16 at 12:46
  • My guess is that your settings function returns string value which is not accepted as width/height (you should see an error in the output in this case). Try javascript's parseInt() function if this is the problem. Anyway, try to debug values that are returned by your settings function. – rsht May 04 '16 at 12:50

0 Answers0