QtQuick 2.0下拉按钮

时间:2013-10-27 16:23:25

标签: qt qt-quick qtquick2

我有一个工具栏ToolBar,我想要一个下拉按钮。

我尝试使用ComboBox,但按钮的大小按列表模型项的长度调整大小。我不知道如何对点击事件采取行动。

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
  }
}

无论如何,我认为这是一种错误的做法。

使用QtQuck 2.0轻松创建下拉按钮的任何方法?

1 个答案:

答案 0 :(得分:0)

您正在将label属性直接指定给ToolButton。 Qml没有选项来填充空间但是拉伸按钮。试试这样的事情。

在主qml文件中

    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
        }
    }
}
相关问题