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. QML version of QRubberBand
Qt 6.11 is out! See what's new in the release blog

QML version of QRubberBand

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 1.5k Views
  • 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.
  • E Offline
    E Offline
    elderorb
    wrote on last edited by
    #1

    Is it possible to implement QML version of QRubberBand ? I mean fully
    QML, without any widgets dependency?

    I understand it is trivial to make draggable area inside QML window.
    But what about draggable area over the whole screen? Should I create
    separate invisible QML window with the geometry of the screen and just
    put draggable rectangle inside or better approach exists?

    E 1 Reply Last reply
    0
    • E elderorb

      Is it possible to implement QML version of QRubberBand ? I mean fully
      QML, without any widgets dependency?

      I understand it is trivial to make draggable area inside QML window.
      But what about draggable area over the whole screen? Should I create
      separate invisible QML window with the geometry of the screen and just
      put draggable rectangle inside or better approach exists?

      E Offline
      E Offline
      elderorb
      wrote on last edited by elderorb
      #2

      I've made some experiments and got basic rubber band working using
      additional QML Window. But the issue I confronted is that
      transparency/opacity on Windows 7 (and Windows 10) seems to be broken.
      As soon as I start re-sizing area, opacity and transparency seems to
      be reset and instead of nice semi-transparent rectangle I see ugly
      opaque items... I can only hope I'm doing something wrong otherwise
      seems like major issue in Qt :( Just in case, here is the code of
      'main.qml':

      import QtQuick 2.5
      import QtQuick.Window 2.2
      import QtQuick.Controls 1.4
      
      
      Window {
          id: root
          visible: true
          Button {
              text: "show rubber"
              onClicked: {
                  root.visible = false
                  var rubberBand = rubberBandFactory.createObject(null);
                  rubberBand.visible = true
                  rubberBand.onAreaSelected.connect(function(x, y, w, h) {
                      console.log(x, y, w, h)
                      root.visible = true
                  })
              }
          }
      
      
          property var rubberBandFactory: Component {
      
              Window {
                  id: rubber
                  visible: true
                  flags: Qt.FramelessWindowHint | Qt.Popup
                  modality: Qt.NonModal
                  width: Screen.width
                  height: Screen.height
                  color: "red"
                  opacity: 0.2
      
                  signal areaSelected(int x, int y, int width, int height);
                  property bool initialPosSelected: false;
      
                  MouseArea {
                      id: mouseArea
                      anchors.fill: parent
                      hoverEnabled: false
      
                      onPressed: {
                          marker.x = mouseArea.mouseX
                          marker.y = mouseArea.mouseY
                          hoverEnabled = true;
                      }
      
      
                      onPositionChanged: {
                          marker.width = mouseArea.mouseX - marker.x
                          marker.height = mouseArea.mouseY - marker.y
                      }
      
      
                      onReleased: {
                          hoverEnabled = false
                          rubber.visible = false
                          areaSelected(marker.x, marker.y, marker.width,
      marker.height)
                      }
                  }
      
      
                  Rectangle {
                      id: marker
                      width: 0
                      height: 0
                      color: 'green'
                  }
              }
          }
      }
      ...
      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