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. where to apply MouseArea

where to apply MouseArea

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 357 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I'm trying to implement a seemingly simple Popup that will look like this:
    Screenshot 2023-11-06 110527.png
    The outline of the component is as follows:

    Popup {
        id: popup
        background: Pane {
            Rectangle {}
            Rectangle {}
            Rectangle {}
            Rectangle {}
        }
        contentItem: Pane {
            ColumnLayout {
                RowLayout {
                    Image {}
                    Label {}
                }
                RowLayout {
                    Image {}
                    Label {}
                }
            }
        }
    }
    

    I need to set a MouseArea on this, but can't figure out where/how to do it. Any suggestions?

    Thanks...

    1 Reply Last reply
    0
    • mzimmersM mzimmers

      @Marko-Stanke I tried that:

      Popup {
          id: popup
          implicitHeight: 96
          implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                                  implicitContentWidth + leftPadding + rightPadding)
          padding: 0
      
          contentItem: Pane {
              verticalPadding: 0
              anchors.fill: parent
              anchors.centerIn: parent
              implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                                      implicitContentWidth + leftPadding + rightPadding)
              Item {
                  anchors.fill: parent
                  width: popup.width
                  ColumnLayout {
                      anchors.fill: parent
                      spacing: 0
                      RowLayout {
                          Image {}
                          MultiEffect {}
                          Label {}
                      }
      
                      RowLayout {
                          Image {}
                          MultiEffect {}
                          Label {}
                      }
                  }
                  MouseArea {
                      anchors.fill: parent
                      onClicked: console.log("clicked")
                  }
              }
          }
      }
      

      But the addition of the MouseArea shrinks my background for some reason:
      Screenshot 2023-11-06 123114.png
      (I put the black outline in around the background to make it easier to see what's happening.)
      I don't know why it would be doing this...

      mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #4

      I don't know if this is the best solution, but it works for me (outline only):

      Popup {
          ColumnLayout {
              Rectangle {
                  RowLayout {}
                  MouseArea {
                      anchors.fill: parent
                      onClicked: console.log("clicked")
                  }
              }
          }
      }
      
      1 Reply Last reply
      0
      • Marko StankeM Offline
        Marko StankeM Offline
        Marko Stanke
        wrote on last edited by
        #2

        The example you posted looks like a lot like a Menu ( Which is a subclass of Popup ). So I would recommend to check out the implementation of Menu.qml inside Qt.

        But to answer your question: You would need to define a parent Item. Something like this:

        contentItem: Pane {
                    Item {
                        height: 50
                        width: 100
                        RowLayout {
                            anchors.fill: parent
                            Image {}
                            Label {}
                        }
                        MouseArea {
                            anchors.fill: parent
                            hoverEnabled: true
                            onClicked: {}
                         }
                    }
                }
            }
        
        mzimmersM 1 Reply Last reply
        0
        • Marko StankeM Marko Stanke

          The example you posted looks like a lot like a Menu ( Which is a subclass of Popup ). So I would recommend to check out the implementation of Menu.qml inside Qt.

          But to answer your question: You would need to define a parent Item. Something like this:

          contentItem: Pane {
                      Item {
                          height: 50
                          width: 100
                          RowLayout {
                              anchors.fill: parent
                              Image {}
                              Label {}
                          }
                          MouseArea {
                              anchors.fill: parent
                              hoverEnabled: true
                              onClicked: {}
                           }
                      }
                  }
              }
          
          mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #3

          @Marko-Stanke I tried that:

          Popup {
              id: popup
              implicitHeight: 96
              implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                                      implicitContentWidth + leftPadding + rightPadding)
              padding: 0
          
              contentItem: Pane {
                  verticalPadding: 0
                  anchors.fill: parent
                  anchors.centerIn: parent
                  implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                                          implicitContentWidth + leftPadding + rightPadding)
                  Item {
                      anchors.fill: parent
                      width: popup.width
                      ColumnLayout {
                          anchors.fill: parent
                          spacing: 0
                          RowLayout {
                              Image {}
                              MultiEffect {}
                              Label {}
                          }
          
                          RowLayout {
                              Image {}
                              MultiEffect {}
                              Label {}
                          }
                      }
                      MouseArea {
                          anchors.fill: parent
                          onClicked: console.log("clicked")
                      }
                  }
              }
          }
          

          But the addition of the MouseArea shrinks my background for some reason:
          Screenshot 2023-11-06 123114.png
          (I put the black outline in around the background to make it easier to see what's happening.)
          I don't know why it would be doing this...

          mzimmersM 1 Reply Last reply
          0
          • mzimmersM mzimmers

            @Marko-Stanke I tried that:

            Popup {
                id: popup
                implicitHeight: 96
                implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                                        implicitContentWidth + leftPadding + rightPadding)
                padding: 0
            
                contentItem: Pane {
                    verticalPadding: 0
                    anchors.fill: parent
                    anchors.centerIn: parent
                    implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                                            implicitContentWidth + leftPadding + rightPadding)
                    Item {
                        anchors.fill: parent
                        width: popup.width
                        ColumnLayout {
                            anchors.fill: parent
                            spacing: 0
                            RowLayout {
                                Image {}
                                MultiEffect {}
                                Label {}
                            }
            
                            RowLayout {
                                Image {}
                                MultiEffect {}
                                Label {}
                            }
                        }
                        MouseArea {
                            anchors.fill: parent
                            onClicked: console.log("clicked")
                        }
                    }
                }
            }
            

            But the addition of the MouseArea shrinks my background for some reason:
            Screenshot 2023-11-06 123114.png
            (I put the black outline in around the background to make it easier to see what's happening.)
            I don't know why it would be doing this...

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #4

            I don't know if this is the best solution, but it works for me (outline only):

            Popup {
                ColumnLayout {
                    Rectangle {
                        RowLayout {}
                        MouseArea {
                            anchors.fill: parent
                            onClicked: console.log("clicked")
                        }
                    }
                }
            }
            
            1 Reply Last reply
            0
            • mzimmersM mzimmers has marked this topic as solved on

            • Login

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