0

I have a tool bar ToolBar on which I want to have a drop down button.

I tried to use ComboBox, but the button is resized by the length of the list model items. And I don't know how to put actions on click events.

ToolBar {
  id: toolBar
  anchors.margins: 0
  Layout.fillWidth: true
  layer.enabled: true

  RowLayout {
    ComboBox {
      id: databaseTypeInput

      style: ComboBoxStyle {
        label: ToolButton {
          implicitWidth: 20
          implicitHeight: 20
          iconSource: "Image.png"
        } // ToolButton
      }
    } // ComboBox
  }
}

Anyway I think it is a wrong way of doing this.

Any way to easy create a drop down button with QtQuck 2.0 ?

user14416
  • 2,922
  • 5
  • 40
  • 67

1 Answers1

0

You are assigning label property directly to a ToolButton. Qml has no option to fill it space with but stretching the button. Try Something like this.

Inside your main qml file

    ComboBox {
          id: databaseTypeInput
          width: 100;
          style: ComboBoxStyle {
            label: MyComponent{}
            }
    } // ComboBox

MyComponent.qml

import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.0
import QtQuick.Controls.Styles 1.0

Rectangle {
    width: 100
    height: 62
    RowLayout {
        Button {
            implicitWidth: 20
            implicitHeight: 20
            text: "T"
        }
        Text {
            text: control.currentText
        }
    }
}
Dasun
  • 3,244
  • 1
  • 29
  • 40
  • So there is no way to make drop down button (not stretched) with Qml? – user14416 Nov 28 '13 at 21:15
  • I'm sorry. I may misunderstood your question. I think currently no way to change drop downlist but you can change label of ComboBox. – Dasun Nov 29 '13 at 07:24