qt - QML Form layout (GridLayout) troubles -
i trying convert app ui c++ qml. @ step need login window created in qml code below:
window { id: loginwindow property string username: login.text; property string password: password.text; property bool issave: savepassword.checked; flags: qt.dialog modality: qt.windowmodal width: 400 height: 160 minimumheight: 160 minimumwidth: 400 title: "login program" gridlayout { columns: 2 anchors.fill: parent anchors.margins: 10 rowspacing: 10 columnspacing: 10 label { text: "login" } textfield { id: login text: config.getparam("user") layout.fillwidth: true } label { text: "password" } textfield { id: password text: config.getparam("password") echomode: textinput.password layout.fillwidth: true } label { text: "save password?" } checkbox { id: savepassword } item { layout.columnspan: 2 layout.fillwidth: true button { anchors.centerin: parent text: "enter" onclicked: { loginwindow.close(); } } } } }
i used gridlayout more compatible form layout. window looks not expected. screenshot:
gridlayout has 10px margin , 10px between rows/columns.
but @ screenshot seen row button has neither margins nor spacing.
what wrong?
qt 5.3.0 debian 7.5 x32
the problem item containing button doesn't have height set. type of problem first thing check when debugging layout problems. can printing out geometry of item:
item { layout.columnspan: 2 layout.fillwidth: true component.oncompleted: print(x, y, width, height) button { anchors.centerin: parent text: "enter" onclicked: { loginwindow.close(); } } }
this outputs:
qml: 0 87 118 0
the fix:
item { layout.columnspan: 2 layout.fillwidth: true implicitheight: button.height button { id: button anchors.centerin: parent text: "enter" onclicked: { loginwindow.close(); } } }
the complete code:
import qtquick 2.2 import qtquick.window 2.0 import qtquick.controls 1.1 import qtquick.layouts 1.1 window { id: loginwindow property string username: login.text; property string password: password.text; property bool issave: savepassword.checked; flags: qt.dialog modality: qt.windowmodal width: 400 height: 160 minimumheight: 160 minimumwidth: 400 title: "login program" gridlayout { columns: 2 anchors.fill: parent anchors.margins: 10 rowspacing: 10 columnspacing: 10 label { text: "login" } textfield { id: login text: "blah" layout.fillwidth: true } label { text: "password" } textfield { id: password text: "blah" echomode: textinput.password layout.fillwidth: true } label { text: "save password?" } checkbox { id: savepassword } item { layout.columnspan: 2 layout.fillwidth: true implicitheight: button.height button { id: button anchors.centerin: parent text: "enter" onclicked: { loginwindow.close(); } } } } }
Comments
Post a Comment