0

I am using QtQuick.Controls 1.0 and QtQuick.Controls.Styles 1.0 and I can't find a way to properly align the label of the ComboBox vertically and on the right.

This is my current code

import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.0


ComboBox {
  id: comboCategories
  width: 230
  height: 30

  style: ComboBoxStyle {
    background: Rectangle {
      id: rectCategory
      width: comboCategories.width
      height: comboCategories.height
      color: "white"
    }

    label: Text {
      anchors.verticalCenter: parent.verticalCenter
      anchors.right: background.right
      font.pointSize: 12
      color: "#808080"
      text: control.currentText
    }
  }
}

But the label stays in the top left of my element and does not seem to be affected by the anchors. I also tried to replace parent with control or background with no effect

1 Answer 1

1

I don't exactly know the reasoning behind this but if I wrap my Text element in an Item then I can properly

import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.0

ComboBox {
  id: comboCategories
  width: 230
  height: 30

  style: ComboBoxStyle {
    background: Rectangle {
      id: rectCategory
      width: comboCategories.width
      height: comboCategories.height
      color: "white"
    }

    label: Item {
      anchors.fill: parent
      Text {
        anchors.verticalCenter: parent.verticalCenter
        anchors.right: parent.right
        anchors.rightMargin: 5
        font.pointSize: 12
        color: "#808080"
        text: control.currentText
      }
  }
}

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.