Once qml widget lost the focus, It cannt get the focus again
-
At first. my qml widget has focus.
After I open another application, my qml widget lost the focus.
I clicked my qml widget, it didn't do any response, I'm sure it didnt died.
This is my qml code.import QtQuick 1.1
Rectangle {
id: mainWindow
objectName: "toolBarQml"
border.color: "#0080FF"
border.width: 0
width: 192
height: 31BorderImage { visible : true anchors.fill: parent border { left: mainSkin.marginLeft; top: mainSkin.marginTop; right: mainSkin.marginRight; bottom: mainSkin.marginBottom; } horizontalTileMode: mainSkin.horizontalTileMode verticalTileMode: mainSkin.verticalTileMode source: mainSkin.mainBackImg } Image { id: logo visible : true source: mainSkin.mainLogoImg opacity: 1 } MouseArea { anchors.fill: parent property variant previousPosition onPressed: { previousPosition = Qt.point(mouseX, mouseY) } onPositionChanged: { if (pressedButtons == Qt.LeftButton) { var dx = mouseX - previousPosition.x var dy = mouseY - previousPosition.y var y = mainWidget.pos.y + dy var x = mainWidget.pos.x + dx var final_y,final_x ; if(Number(y) > Number(mainModel.bottomLimit)) { final_y = mainModel.bottomLimit; }else if(y < 0) { final_y = 0; } else { final_y = y; } if(Number(x) > Number(mainModel.rightLimit)) { final_x = mainModel.rightLimit; } else if(Number(x) < 0) { final_x = 0; } else { final_x = x; } mainWidget.pos = Qt.point(final_x, final_y) } } } Image { id: cn visible : true source: mainModel.wb?(mainModel.cn? mainSkin.mainWbImg : mainSkin.mainEngImg):(mainModel.cn? mainSkin.mainCnImg : mainSkin.mainEngImg); opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 console.log(mainModel.wb) } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 mainCtrl.changeCnMode(!mainModel.cn); } onPressed: { parent.scale = 0.9 } } } Image { id: trad source: mainModel.trad ? mainSkin.mainTraditionalImg : mainSkin.mainSimplifiedImg; visible: !mainModel.wb opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 mainCtrl.changeTrad(!mainModel.trad) } onPressed: { parent.scale = 0.9 } } } Image { id: fullwidth source: mainModel.fullwidth ? mainSkin.mainFullWidthImg : mainSkin.mainHalfWidthImg; opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 mainCtrl.changeFullWidth(!mainModel.fullwidth) } onPressed: { parent.scale = 0.9 } } } Image { id: cnmark source: mainModel.cnMark ? mainSkin.mainCnMarkImg : mainSkin.mainEngMarkImg; opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 mainCtrl.changePunc(!mainModel.cnMark) } onPressed: { parent.scale = 0.9 } } }
// Image {
// id: softkbd
// source: mainSkin.mainSoftKbdImg;
// opacity: 1
// MouseArea {
// anchors.fill: parent
// hoverEnabled: true
// onEntered: {
// parent.opacity = 0.6
// }
// onExited: {
// parent.scale = 1;
// parent.opacity = 1
// }
// onClicked: {
// parent.scale = 1;
// parent.opacity = 0.9
// mainCtrl.showSoftKbd(!mainModel.softKbd)
// }
// onPressed: {
// parent.scale = 0.9
// }
// }
// }Image { id: symbols source: mainSkin.mainSymbolsImg; opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 onClicked: mainCtrl.showSymbolsDialog(true) } onPressed: { parent.scale = 0.9 } } } Image { id: setting source: mainSkin.mainSettingImg; opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 onClicked: mainCtrl.showConfigDialog(true) } onPressed: { parent.scale = 0.9 } } } Component.onCompleted: { if(mainModel.wb) { mainWindow.width = 167; setObjAbsolutePosition(logo, 8, 4); setObjAbsolutePosition(cn, 42, 4); setObjAbsolutePosition(trad, 67, 4); setObjAbsolutePosition(fullwidth, 67, 4); setObjAbsolutePosition(cnmark, 92, 4); setObjAbsolutePosition(symbols, 117, 4); setObjAbsolutePosition(setting, 142, 4); } else { setObjAbsolutePosition(logo, 8, 4); setObjAbsolutePosition(cn, 42, 4); setObjAbsolutePosition(trad, 67, 4); setObjAbsolutePosition(fullwidth, 92, 4); setObjAbsolutePosition(cnmark, 117, 4); setObjAbsolutePosition(symbols, 142, 4); setObjAbsolutePosition(setting, 167, 4); } } function setObjAbsolutePosition(bindObj, x, y) { if (x > 0) { bindObj.anchors.left = mainWindow.left; bindObj.anchors.leftMargin = x; } else if (x < 0) { bindObj.anchors.right = mainWindow.right; bindObj.anchors.rightMargin = -x; } if (y > 0) { bindObj.anchors.top = mainWindow.top; bindObj.anchors.topMargin = y; } else if (y < 0) { bindObj.anchors.bottom = mainWindow.bottom; bindObj.anchors.bottomMargin = -y; } }
}
-
At first. my qml widget has focus.
After I open another application, my qml widget lost the focus.
I clicked my qml widget, it didn't do any response, I'm sure it didnt died.
This is my qml code.import QtQuick 1.1
Rectangle {
id: mainWindow
objectName: "toolBarQml"
border.color: "#0080FF"
border.width: 0
width: 192
height: 31BorderImage { visible : true anchors.fill: parent border { left: mainSkin.marginLeft; top: mainSkin.marginTop; right: mainSkin.marginRight; bottom: mainSkin.marginBottom; } horizontalTileMode: mainSkin.horizontalTileMode verticalTileMode: mainSkin.verticalTileMode source: mainSkin.mainBackImg } Image { id: logo visible : true source: mainSkin.mainLogoImg opacity: 1 } MouseArea { anchors.fill: parent property variant previousPosition onPressed: { previousPosition = Qt.point(mouseX, mouseY) } onPositionChanged: { if (pressedButtons == Qt.LeftButton) { var dx = mouseX - previousPosition.x var dy = mouseY - previousPosition.y var y = mainWidget.pos.y + dy var x = mainWidget.pos.x + dx var final_y,final_x ; if(Number(y) > Number(mainModel.bottomLimit)) { final_y = mainModel.bottomLimit; }else if(y < 0) { final_y = 0; } else { final_y = y; } if(Number(x) > Number(mainModel.rightLimit)) { final_x = mainModel.rightLimit; } else if(Number(x) < 0) { final_x = 0; } else { final_x = x; } mainWidget.pos = Qt.point(final_x, final_y) } } } Image { id: cn visible : true source: mainModel.wb?(mainModel.cn? mainSkin.mainWbImg : mainSkin.mainEngImg):(mainModel.cn? mainSkin.mainCnImg : mainSkin.mainEngImg); opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 console.log(mainModel.wb) } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 mainCtrl.changeCnMode(!mainModel.cn); } onPressed: { parent.scale = 0.9 } } } Image { id: trad source: mainModel.trad ? mainSkin.mainTraditionalImg : mainSkin.mainSimplifiedImg; visible: !mainModel.wb opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 mainCtrl.changeTrad(!mainModel.trad) } onPressed: { parent.scale = 0.9 } } } Image { id: fullwidth source: mainModel.fullwidth ? mainSkin.mainFullWidthImg : mainSkin.mainHalfWidthImg; opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 mainCtrl.changeFullWidth(!mainModel.fullwidth) } onPressed: { parent.scale = 0.9 } } } Image { id: cnmark source: mainModel.cnMark ? mainSkin.mainCnMarkImg : mainSkin.mainEngMarkImg; opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 mainCtrl.changePunc(!mainModel.cnMark) } onPressed: { parent.scale = 0.9 } } }
// Image {
// id: softkbd
// source: mainSkin.mainSoftKbdImg;
// opacity: 1
// MouseArea {
// anchors.fill: parent
// hoverEnabled: true
// onEntered: {
// parent.opacity = 0.6
// }
// onExited: {
// parent.scale = 1;
// parent.opacity = 1
// }
// onClicked: {
// parent.scale = 1;
// parent.opacity = 0.9
// mainCtrl.showSoftKbd(!mainModel.softKbd)
// }
// onPressed: {
// parent.scale = 0.9
// }
// }
// }Image { id: symbols source: mainSkin.mainSymbolsImg; opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 onClicked: mainCtrl.showSymbolsDialog(true) } onPressed: { parent.scale = 0.9 } } } Image { id: setting source: mainSkin.mainSettingImg; opacity: 1 MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { parent.opacity = 0.6 } onExited: { parent.scale = 1; parent.opacity = 1 } onClicked: { parent.scale = 1; parent.opacity = 0.9 onClicked: mainCtrl.showConfigDialog(true) } onPressed: { parent.scale = 0.9 } } } Component.onCompleted: { if(mainModel.wb) { mainWindow.width = 167; setObjAbsolutePosition(logo, 8, 4); setObjAbsolutePosition(cn, 42, 4); setObjAbsolutePosition(trad, 67, 4); setObjAbsolutePosition(fullwidth, 67, 4); setObjAbsolutePosition(cnmark, 92, 4); setObjAbsolutePosition(symbols, 117, 4); setObjAbsolutePosition(setting, 142, 4); } else { setObjAbsolutePosition(logo, 8, 4); setObjAbsolutePosition(cn, 42, 4); setObjAbsolutePosition(trad, 67, 4); setObjAbsolutePosition(fullwidth, 92, 4); setObjAbsolutePosition(cnmark, 117, 4); setObjAbsolutePosition(symbols, 142, 4); setObjAbsolutePosition(setting, 167, 4); } } function setObjAbsolutePosition(bindObj, x, y) { if (x > 0) { bindObj.anchors.left = mainWindow.left; bindObj.anchors.leftMargin = x; } else if (x < 0) { bindObj.anchors.right = mainWindow.right; bindObj.anchors.rightMargin = -x; } if (y > 0) { bindObj.anchors.top = mainWindow.top; bindObj.anchors.topMargin = y; } else if (y < 0) { bindObj.anchors.bottom = mainWindow.bottom; bindObj.anchors.bottomMargin = -y; } }
}
@chris_rookie said in Once qml widget lost the focus, It cannt get the focus again:
onClicked: {
parent.scale = 1;
parent.opacity = 0.9
onClicked: mainCtrl.showConfigDialog(true)
}this is syntax error
-
@chris_rookie said in Once qml widget lost the focus, It cannt get the focus again:
onClicked: {
parent.scale = 1;
parent.opacity = 0.9
onClicked: mainCtrl.showConfigDialog(true)
}this is syntax error
@LeLev said in Once qml widget lost the focus, It cannt get the focus again:
mainCtrl.showConfigDialog(true)
Hi,
Do you mean that I should
change onClicked: mainCtrl.showConfigDialog(true)
to mainCtrl.showConfigDialog(true)mToolBarView = new QDeclarativeView; mToolBarView->setResizeMode(QDeclarativeView::SizeViewToRootObject); mToolBarView->setResizeAnchor(QGraphicsView::AnchorViewCenter); mToolBarView->viewport()->setAutoFillBackground(false); qmlFile = "qrc:/toolbar4.qml"; mToolBarView->setContentsMargins(0, 0, 0, 0); mToolBarView->rootContext()->setContextProperty("mainCtrl", this); mToolBarView->rootContext()->setContextProperty("mainModel", mToolBarModel); mToolBarView->rootContext()->setContextProperty("mainSkin", (QObject*)mSkinBase); mToolBarView->rootContext()->setContextProperty("mainWidget", mToolBarTopLevel); mToolBarView->setSource(QUrl(qmlFile));
mToolBarTopLevel->setCenterWidget(mToolBarView);
void MainController::showConfigDialog(bool show)
{pid_t pid = fork(); if (pid == 0) { int ret = execlp("config-tools", "config-tools", "14760634-a01a-4919-872a-f5844996b1d2", NULL); if (ret == -1) { qDebug() << "Open config tool failed!"; } exit(EXIT_SUCCESS); }
}
It be used to call a c++ function.
-
@chris_rookie said in Once qml widget lost the focus, It cannt get the focus again:
onClicked: {
parent.scale = 1;
parent.opacity = 0.9
onClicked: mainCtrl.showConfigDialog(true)
}In this part you are on JavaScript scope already, so you cannot use ":". The app will launch and when you click the button you'll receive an error message... However, QML does not crash for these kinds of errors. It will just send you the message and stop any kind of process you were doing with that action. If you change your code to:
onClicked: {
parent.scale = 1;
parent.opacity = 0.9
mainCtrl.showConfigDialog(true)
}It should not show any error and your program would continue normal execution.
-
@chris_rookie said in Once qml widget lost the focus, It cannt get the focus again:
onClicked: {
parent.scale = 1;
parent.opacity = 0.9
onClicked: mainCtrl.showConfigDialog(true)
}In this part you are on JavaScript scope already, so you cannot use ":". The app will launch and when you click the button you'll receive an error message... However, QML does not crash for these kinds of errors. It will just send you the message and stop any kind of process you were doing with that action. If you change your code to:
onClicked: {
parent.scale = 1;
parent.opacity = 0.9
mainCtrl.showConfigDialog(true)
}It should not show any error and your program would continue normal execution.
@rrlopez
Thanks for your answer.