Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Once qml widget lost the focus, It cannt get the focus again
Forum Updated to NodeBB v4.3 + New Features

Once qml widget lost the focus, It cannt get the focus again

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 513 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chris_rookie
    wrote on last edited by
    #1

    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: 31

    BorderImage {
        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;
        }
    }
    

    }

    ODБOïO 1 Reply Last reply
    0
    • C chris_rookie

      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: 31

      BorderImage {
          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;
          }
      }
      

      }

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @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

      C 1 Reply Last reply
      0
      • ODБOïO ODБOï

        @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

        C Offline
        C Offline
        chris_rookie
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • rrlopezR Offline
          rrlopezR Offline
          rrlopez
          wrote on last edited by
          #4

          @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.

          Lic-Ing. Rodrigo Lopez Gonzalez
          Embedded Software Engineer
          RidgeRun Engineering Ltd.
          www.ridgerun.com
          Email: rodrigo.lopez@ridgerun.com

          C 1 Reply Last reply
          0
          • rrlopezR rrlopez

            @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.

            C Offline
            C Offline
            chris_rookie
            wrote on last edited by
            #5

            @rrlopez
            Thanks for your answer.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved