19 Replies Latest reply: Mar 3, 2013 7:17 AM by dishooom RSS

maxWidth is NOT set

allsystemgo Novice

I've been getting this error message in my terminal:

 

 default 9000 "WARNING: maxWidth is NOT set, returned value cannot be trusted"

 

I know what it means but I have no clue where to set it or which one is giving me the error in my QML. can anyone tell me how to figure out which control is giving me the error.

 

Thank you

  • Re: maxWidth is NOT set
    Novice

    I doubt if this is an error and more like a WARNING given when trying to access/use a property (getMinWidth()) that has not been already set...

    • Re: maxWidth is NOT set
      allsystemgo Novice
      you are right it's not an error it's a warning I get in the terminal but I would like to remove them so that's why I was asking. I always feel like I'm falling when my projects aren't compiling without error/warning
      • Re: maxWidth is NOT set
        Novice

        TO know the exact cause of the warning.. i guess you ll have to share the code... Smiley Happy

        • Re: maxWidth is NOT set
          oliver.kranz Novice

          Select maxWidth or write it in a comment and select it.

           

          // maxWidth

          Then in Momentics select Search > Text > Project. In the search results you will see all occurrences of maxWidth. Then you can eliminate where you access it.

          • Re: maxWidth is NOT set
            allsystemgo Novice

            Ok I finally understood by reading all your posts. I was setting, in my QML, preferredWidth: maxWidth. I was doing this cause I thought it would use the complete width available. As soon as I commented that the Warnings went away. Is there something else I need to do in preferredWidth so that the container use the full width available, or by default if nothing the complete space is taken ?

            • Re: maxWidth is NOT set
              peter9477- Master
              Instead of setting preferredWidth to maxWidth, use preferredWidth: Infinity

              The maxWidth will, if set, still override that of course.
              • Re: maxWidth is NOT set
                allsystemgo Novice
                Thnak you Peter
                • Re: maxWidth is NOT set
                  allsystemgo Novice

                  I tried your Infinity variable but it squishes out my image. Here is a sample code

                   

                  import bb.cascades 1.0
                  
                  Container {
                      layout: StackLayout {
                          orientation: LayoutOrientation.TopToBottom
                      }
                      preferredHeight: 150
                      preferredWidth: Infinity
                      Container {
                          layout: StackLayout {
                              orientation: LayoutOrientation.LeftToRight
                          }
                          bottomPadding: 10
                          topPadding: 10
                          leftPadding: 10
                          ImageView {
                              preferredHeight: 80
                              preferredWidth: 80
                              imageSource: "asset:///images/following.png"
                          }
                          Container {
                              layout: DockLayout {
                              }
                              preferredHeight: 80
                              //preferredWidth: 600 
                              Label {
                                  verticalAlignment: VerticalAlignment.Bottom
                                  text: "Test"
                              }
                              Label {
                                  translationX: 100
                                  verticalAlignment: VerticalAlignment.Bottom
                                  text: "Test2"
                              }
                          }
                      }
                  }

                   Here my problem is if I don't set the third container to a preferedWidth: 600 I don't get to see the Test2. And if I set the preferedWidth: Infinity instead of 600 my image on the left is getting squished. Is it me that don't understand how it's suppose to work?

                   

                  Thank you

                  • Re: maxWidth is NOT set
                    peter9477- Master
                    The preferredWidth: Infinity trick is, I believe, mainly useful in a ListView when you put it on the root visual node for a custom ListItemComponent. I'm not sure why I suggested it here without any sign you were working with a ListView.

                    For other cases, there should be no need of that. I think you're dealing with instances where you should be adding a layoutProperties element, probably layoutProperties: StackLayoutProperties { spaceQuota: 1}.  You'd do that for example in one of the items in a StackLayout to have it expand in the layout direction to fill the space remaining after other items were given their preferred widths.

                    Alternatively, if you're trying to expand something to fill the available space *perpendicular to* the layout direction, then you'd probably want the horizontalAlignment: HorizontalAlignment.Fill to expand across the width when doing a TopToBottom layout (or the vertical equivalent to expand to the full height when doing a LeftToRight layout).