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. How do I make a mouse click on one delegate and then highlight the other delegates with it?
Forum Updated to NodeBB v4.3 + New Features

How do I make a mouse click on one delegate and then highlight the other delegates with it?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 540 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.
  • B Offline
    B Offline
    ButterBoubon
    wrote on last edited by
    #1

    Hi Guys

    Thanks for the great forum, it's helped a lot so far on my Qt journey. I couldn't find a solution to the following problem though.

    Item {
            Grid{
                spacing: 2
                columns: 10
                Repeater {
                    model: 100
                    delegate: Rectangle{
                        height: 20
                        width: 20
                        property bool colorBool: false
                        color: colorBool? "yellow" : "red"
                        MouseArea {
                            onClicked: colorBool = !colorBool
                        }
                    }
                }
            }
    

    I want to be able to click the mouse to change the color on one delegate, than without releasing the click move through the other delegates and have them change color too until I release the mouse click. Like drawing on very large pixels.
    Also to change the color back the same way, like an eraser.

    I've tried many things for many hours, I can't seem to figure anything out.

    Thanks!

    1 Reply Last reply
    0
    • W Offline
      W Offline
      while1code
      wrote on last edited by while1code
      #2

      https://qmlweb.github.io/

      import QtQuick 2.0
      
      
      Rectangle {
        id:root
        width: 500+5; height: width
        property bool press : false
        color: "green"
      	function draw(_it){
            if(_it.color=="green"){
            _it.color="red"
            }
            else{
            	_it.color="green"
            }
          }
      
        Grid{
        	height:500
          width:500
          columns:5
          spacing : 1
      	Repeater{
          	model:25
            	Rectangle{
                id:rec
              	height:100
                  width:100
                  color:"red"
                MouseArea{
                  id:m
                	anchors.fill:parent
                  hoverEnabled:true
                  onClicked:{if(press)press=false;else press=true}
                 
                  onEntered:{
                    if(root.press==true)
                  	draw(rec)
                  }
                }
                
              }
          }    
        	
        }
      }
      

      if you want to hold mouse for drawing, you can put mouseX and mouseY as top level properties and check in your delegate if the coordinates are inside your delegate , that is some maths. i can help if you have probleme. but now i just reset my computer so i have to install Qt +creator

      1 Reply Last reply
      1
      • B Offline
        B Offline
        ButterBoubon
        wrote on last edited by
        #3

        Thank you!

        That's pretty cool. I was sort of on the right track with something similar, but I don't think I would have figured out.

        I'm going to play with it a bit to get it just how I need it.

        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