Skip to content

Instantly share code, notes, and snippets.

@mitchcurtis
Last active July 6, 2021 14:09
Show Gist options
  • Save mitchcurtis/b8baca8be443e940dc2c4d99bcc865cb to your computer and use it in GitHub Desktop.
Save mitchcurtis/b8baca8be443e940dc2c4d99bcc865cb to your computer and use it in GitHub Desktop.
ListView with array model of copyable colours
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
ApplicationWindow {
id: window
width: 600
height: 600
visible: true
title: "colours"
ListView {
id: listView
anchors.fill: parent
boundsBehavior: ListView.StopAtBounds
ScrollBar.vertical: ScrollBar {}
model: [
"#111111",
"#222222",
"#333333",
"#444444",
"#111111",
"#222222",
"#333333",
"#444444",
"#111111",
"#222222",
"#333333",
"#444444",
"#111111",
"#222222",
"#333333",
"#444444",
"#111111",
"#222222",
"#333333",
"#444444"
]
delegate: Rectangle {
id: root
width: listView.width
height: row.implicitHeight * 1.5
color: modelData
RowLayout {
id: row
anchors.centerIn: parent
spacing: 40
TextInput {
text: root.color
font.pixelSize: Qt.application.font.pixelSize * 1.5
color: "white"
readOnly: true
selectByMouse: true
Layout.fillWidth: true
}
TextInput {
text: "(" + root.color.r.toFixed(2) + ", " + root.color.g.toFixed(2) + ", " + root.color.b.toFixed(2) + ")"
font.pixelSize: Qt.application.font.pixelSize * 1.5
color: "white"
readOnly: true
selectByMouse: true
Layout.fillWidth: true
}
TextInput {
text: "(" + Math.floor(root.color.r * 255) + ", " + Math.floor(root.color.g * 255) + ", " + Math.floor(root.color.b * 255) + ")"
font.pixelSize: Qt.application.font.pixelSize * 1.5
color: "white"
readOnly: true
selectByMouse: true
Layout.fillWidth: true
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment