Advertisement
Guest User

Qml ComboBox Style

a guest
Jun 16th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 3.12 KB | None | 0 0
  1. import QtQuick 2.4
  2. import QtQuick.Controls.Styles 1.3
  3. import QtQuick.Controls.Private 1.0
  4. import QtGraphicalEffects 1.0
  5.  
  6. ComboBoxStyle {
  7.     background: Rectangle {
  8.         radius: 2
  9.         color: control.enabled ? "#fafafa": "#c7c7c7"
  10.         border.width: 1
  11.         border.color: control.enabled ? "#000000" : "#c7c7c7"
  12.     }
  13.  
  14.     label: Item {
  15.         implicitHeight: 42 - padding.top - padding.bottom
  16.         anchors.rightMargin: 10
  17.  
  18.         Text {
  19.             text: control.currentText
  20.             font.pixelSize: 17
  21.             font.family: "Ubuntu"
  22.             verticalAlignment: Text.AlignVCenter
  23.             anchors.verticalCenter: parent.verticalCenter
  24.             color: control.enabled ? "#000000" : "#484848"
  25.         }
  26.  
  27.         Image {
  28.             id: downIcon
  29.             width: source != "" ? 15 : 0
  30.             height: width
  31.             source: "qrc:/icons/down-arrow.svg"
  32.             anchors.right: parent.right
  33.             anchors.verticalCenter: parent.verticalCenter
  34.         }
  35.  
  36.         ColorOverlay {
  37.             anchors.fill: downIcon
  38.             source: downIcon
  39.             color: "#000000"
  40.         }
  41.     }
  42.  
  43.     property Component __dropDownStyle: MenuStyle {
  44.         __maxPopupHeight: 228
  45.         __menuItemType: "comboboxitem"
  46.  
  47.         frame: Rectangle {
  48.             radius: 2
  49.             color: "#fafafa"
  50.             border.width: 1
  51.             border.color: "#000000"
  52.         }
  53.  
  54.         itemDelegate.label: Text {
  55.             text: styleData.text
  56.             font.family: "Ubuntu"
  57.             font.pixelSize: 17
  58.             verticalAlignment: Text.AlignVCenter
  59.             color: styleData.selected ? "#000000" : "#000000"
  60.             height: 42 - padding.top - padding.bottom
  61.         }
  62.  
  63.         itemDelegate.background: Rectangle {
  64.             radius: 1
  65.             color: styleData.selected ? "#00897b" : "transparent"
  66.         }
  67.  
  68.         scrollIndicator: Rectangle {
  69.             id: scroll
  70.             height: 21
  71.             color: "#fafafa"
  72.             anchors.margins: 10
  73.  
  74.             Image {
  75.                 id: scrollImage
  76.                 anchors.centerIn: parent
  77.                 width: source != "" ? 20 : 0
  78.                 height: width
  79.                 source: styleData.scrollerDirection === Qt.UpArrow ? "qrc:/icons/up-arrow.svg" :
  80.                         styleData.scrollerDirection === Qt.DownArrow ? "qrc:/icons/down-arrow.svg" : ""
  81.             }
  82.  
  83.             ColorOverlay {
  84.                 anchors.fill: scrollImage
  85.                 source: scrollImage
  86.                 color: "#000000"
  87.             }
  88.  
  89.             MouseArea {
  90.                 id: scrollMouseArea
  91.                 anchors.fill: parent
  92.                 hoverEnabled: true
  93.                 visible: false
  94.                 onEntered: parent.color = "#42a5f5"
  95.                 onExited: parent.color = "#fafafa"
  96.                 onPressed: parent.color = "#42a5f5"
  97.                 onReleased: parent.color = "#fafafa"
  98.  
  99.                 Timer {
  100.                     interval: 10; running: true
  101.                     onTriggered: parent.visible = true
  102.                 }
  103.             }
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement