0

I have made an app with this source code: http://pastebin.com/zMwtusZJ However when I try to run the app the webview instead becomes black and does not load the web page.

Here is the crash output: http://pastebin.com/AjDjadEP

When I define a width for the webview element with something like->width:units.gu(160) Then it works just fine.However if possible I would prefer it to use the full height of the parent.

Here is the fixed and improved source: http://pastebin.com/6UyMF9Tb

1 Answer 1

0

I was unable to reproduce your problem, but when I ran your sample, I didn't see the webview at all. It looks to me that your positioning is very confused. You have a Column containing a single Row, which contains another Column. This doesn't really make sense. It's obscured by incorrect indentation, so the first take-away is, clean up your code before you post it. Not only will it help those trying to help you, you may discover the problem in the process.

You are mixing positioning by explicit sizing and anchoring. For example, your outer column has both the width set explicitly and implicitly, through the anchor.fill attribute. Do you know which one will win if they disagree? I sure don't.

Along a similar line, you set the width of the WebView to be the width of its parent, the Row. But the Row has to be wide enough to hold all of its children, so it must be wider than the WebView. How does QML resolve this? I don't know. I find Row and Column good for arranging a number of Elements of known size, but not for holding elements that should take up the remaining space. If that's what you want, do it explicitly or through anchors.

Below, I've rewritten your example code into a form that works for me. I don't know that this was the layout you were trying for, but hopefully it's clear enough for you to rearrange it as you see fit.

I chose to put the URL entry and the buttons in a Row, since all of them are of a fixed size. The WebView should take up the rest of the space, so I anchor its top to the bottom of the Row (with a 1 gu margin) and its bottom to the bottom of the Page. Setting its width to the Page width ensures that it reaches all the way across, although that could also have been accomplished with anchors.

import QtQuick 2.0
import Ubuntu.Components 1.1
import com.canonical.Oxide 1.0
import QtQuick.Window 2.0

MainView {
    applicationName: "com.ubuntu.developer.mkamenjak77.bugapp"
    useDeprecatedToolbar: false
    width: Screen.width/2
    height: Screen.height/2

    Page {
        Row{
            id: controlRow

            TextField {
                id: textfield
                text: "http://google.com"
                width: units.gu(40)

                Keys.onReturnPressed: {
                    if (textfield.text.substring(0, 7) != "http://")
                        textfield.text = "http://" + textfield.text;
                    webview.url = textfield.text
                }
            }

            Button {
                width: units.gu(10)
                text: i18n.tr("Osvježi")
                onClicked: webview.reload()
            }

            Button {
                width: units.gu(10)
                text: i18n.tr("Naprijed")
                onClicked: webview.goForward()
            }

            Button {
                width: units.gu(10)
                text: i18n.tr("Natrag")
                onClicked: webview.goBack()
            }
        }

        WebView {
            id: webview
            width: parent.width
            anchors.top: controlRow.bottom
            anchors.topMargin: units.gu(1)
            anchors.bottom: parent.bottom

            Component.onCompleted: {
                url = textfield.text
            }
        }
    }
}
2
  • In hindsight I really did forget to clean the code,sorry,but it was late already.The layout you made is not even close to what I made.I made a vertical sidebar for the buttons and made the text area also vertical. Dec 1, 2014 at 16:06
  • Update:I cracked it.I forgot to define the width for the row.And now it is working as intended.I will clean the code up and post a solution if I don't forget it. Dec 1, 2014 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .