Полоса прокрутки не отображается

#qml #scrollbar

Вопрос:

Эта полоса прокрутки не отображается, и я не понимаю, почему. В лучшем случае я получил большой красный прямоугольник, но не смог использовать его для горизонтальной прокрутки сетки idRootsGrid. Чего мне не хватает ?

 Flickable {  id: flickable  Layout.alignment: Qt.AlignLeft  Layout.fillWidth: true  Layout.preferredHeight: idRootsGrid.implicitHeight  clip: true  ScrollBar.horizontal: ScrollBar {  //anchors.top: flickable.top  anchors.bottom: flickable.bottom  //anchors.right: flickable.right  //anchors.left: flickable.left  active: true  visible: true  contentItem: Rectangle {  id: contentItem_rect2  radius: implicitHeight / 2  color: "Red"  width: 10 // This will be overridden by the width of the scrollbar  height: 10 // This will be overridden based on the size of the scrollbar  }  //size: 10  width: 5  //height: 10  }  GridLayout {  id: idRootsGrid  columnSpacing: 5  rowSpacing: 10  Layout.alignment: Qt.AlignLeft  rows: 1  ...  

Спасибо!

Ответ №1:

Я обнаружил две проблемы в вашем коде. Основная проблема заключается в том, что содержимое вашей полосы прокрутки должно быть implicitHeight определено. Он использует implicitHeight , а не height определяет, как его нарисовать.

И во-вторых, ваш Фликер должен знать, насколько велико его содержимое, поэтому мне пришлось установить его contentWidth свойство на размер вашей сетки.

 Flickable {  id: flickable  Layout.alignment: Qt.AlignLeft  Layout.fillWidth: true  Layout.preferredHeight: idRootsGrid.implicitHeight  clip: true   contentWidth: idRootsGrid.width   ScrollBar.horizontal: ScrollBar {  anchors.bottom: flickable.bottom  active: true  visible: true   contentItem: Rectangle {  id: contentItem_rect2  radius: implicitHeight / 2  color: "Red"   implicitHeight: 10  }  }  GridLayout { ... } }