Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
QT ComboBox绘制在错误的位置_Qt_Qml_Qt5_Qt Quick_Qt5.6 - Fatal编程技术网

QT ComboBox绘制在错误的位置

QT ComboBox绘制在错误的位置,qt,qml,qt5,qt-quick,qt5.6,Qt,Qml,Qt5,Qt Quick,Qt5.6,Ubuntu 18.04上的Qt5.6.2 我有一个非常简单的组合框 import QtQuick.Controls 1.4 Row{//box Item{width: 0.02 * root.width; height: 1}//space spacing: 0.02 * root.width ComboBox{//Recording type id: typeCombo anchors

Ubuntu 18.04上的Qt5.6.2 我有一个非常简单的
组合框

import QtQuick.Controls 1.4
    Row{//box
        Item{width: 0.02 * root.width;  height: 1}//space
        spacing: 0.02 * root.width

        ComboBox{//Recording type
            id: typeCombo
            anchors.bottom: parent

            currentIndex: 2
            model: ["TOWING", "PRE_FLIGHT_CHECKS", "FLIGHT"]
            width: 0.4 * root.width;  height: 0.15 * root.height
        }

        Rectangle{
            id: rectangle

            width: 0.5 * root.width;  height: 0.15 * root.height
            border{color: 'gray'; width: 0.1 * rectangle.height}
            radius: 0.18 * rectangle.height
            clip: true

            onEnabledChanged:  if(!enabled)  textInput.text = ''
            opacity: enabled? 1: 0.3
            visible: ddsObject.isRecorderStation

            TextInput{
                id: textInput
                anchors.centerIn: parent
                font.pixelSize: 0.6 * rectangle.height
                maximumLength: 100
            }

            MouseArea{
                anchors.fill: parent
                onPressed:  parent.border.color = 'magenta'
                onReleased: parent.border.color = 'gray'
                onCanceled:{parent.border.color = 'gray';  execute()}
                onClicked:  execute()
                function execute(){textInput.forceActiveFocus(Qt.OtherFocusReason)}
            }
        }
    }
但是,单击时,它将在应用程序窗口的右下角绘制。此外,该框架还传达了以下信息:

QmlViewGadgetWidget(0x563561aa31e0) must be a top level window
有没有办法解决这个问题?我希望下拉菜单在
组合框
元素的正下方绘制



可能与……有关。但是,答案说这个问题很久以前就解决了。

您需要将ComboBox锚定到根组件。您可以通过设置属性
archors.centerIn:root

来实现这一点,并提供为什么使用不受支持的Qt版本?支持哪个版本?主要是因为我继承了这段代码,而不是最初创建的.Qt 5.6和
import QtQuick.Controls 1.4
我不会说它完全不受支持。但是现在有了Qt5.11和QtQuickControls 2.x。即使代码不是您的原始代码,也可以考虑将其升级到该级别?谢谢您的建议。我的
组合框
与编辑框
矩形
一起位于一行中。结果返回此消息:“QML行:无法为行内的项目指定左、右、水平中心、填充或中心定位。行将不起作用”。然后,您可以设置属性
archors.verticalCenter:parent.verticalCenter