Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. keyPressEvent in QQuickPaintedItem has stopped working after moving file to StackView
Qt 6.12 LTS is out! See what's new in the release blog

keyPressEvent in QQuickPaintedItem has stopped working after moving file to StackView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 416 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.
  • D Offline
    D Offline
    damian28102000
    wrote on last edited by
    #1

    Hi

    I have a problem with class inherited from class QQuickPaintedItem, after moving file to stackview it has stopped working

    void CoreNode::keyPressEvent(QKeyEvent* pEvent)
    {
        if (mpCurrentNumberBox != nullptr)
        {
            mpCurrentNumberBox->keyPress(pEvent);
            update();
    

    but

    void CoreNode::mousePressEvent(QMouseEvent* pEvent)
    {
        setFocus(true);
        mLastMousePosition = pEvent->pos();
        if (isMouseOnHeader(pEvent->pos()))
        {
            mIsMouseClickedOnHeader = true;
    

    mousePressEvent still works

    main.qml

    Window {
        id: window
        visible: true
        width: 1280
        height: 720
        title: "Block-Based Programming Language"
    
        Cursor {
            id: curs
        }
    
        StackView {
            id: stackView
            anchors.fill: parent
            initialItem: "Tasks.qml"
        }
    
        Component.onCompleted: {
            JS.dbInit()
        }
    
    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      StackView is a focusc scope. The view must have focus == true for the current item to have active focus.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      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
      • Unsolved