【问题标题】:Horizontal listview with vertical text in QmlQml中带有垂直文本的水平列表视图
【发布时间】:2018-03-19 08:35:11
【问题描述】:

我想创建一个带有水平列表视图但垂直文本的列表。就像这样。

我已经写好了代码,如下

ListView {
    id: listView;   
    orientation: ListView.Horizontal  
    delegate: listDelegate;
    ScrollBar.horizontal: bar
    model: ListModel {
        id: phoneModel;
        ListElement{
            name: "wewqeq";
        }
        ListElement{
            name: "rrr";
        }
        ListElement{
            name: "Engine auto stop";
        }
        ListElement{
            name: "wewq";
        }
        ListElement{
            name: "weweqwe";
        }
    }
}

我的代码显示结果

  1. 列表项具有水平视图,但文本相同!如何更改 ListElement 的文本方向?
  2. 栏在底部,我怎样才能让它到顶部?

我的结果是这样的

【问题讨论】:

  • 如果将 Text 元素旋转 90/270 度 rotation: 90

标签: qt qml


【解决方案1】:

您可以使用垂直的ListView 并旋转它:

ListView {
    id: listView
    height: //...
    width: //...
    transformOrigin: Item.TopLeft
    rotation: -90
    y: listView.width
    orientation: ListView.Vertical
    ScrollBar.vertical: ScrollBar{}
}

垂直的ScrollBar 将在顶部变为水平。

【讨论】:

  • 非常感谢。但就我而言,我的列表项资源图像已被旋转!那么还有其他方法可以仅旋转文本吗?
【解决方案2】:
ListView {

id: listView    

delegate: listDelegate

rotation:-90 

model: ListModel {
    id: phoneModel;
    ListElement{
        name: "wewqeq";
    }
    ListElement{
        name: "rrr";
    }
    ListElement{
        name: "Engine auto stop";
    }
    ListElement{
        name: "wewq";
    }
    ListElement{
        name: "weweqwe";
    }
  }
 }

【讨论】:

  • 非常感谢。但就我而言,我的列表项资源图像已被旋转!那么还有其他方法可以仅旋转文本吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-15
相关资源
最近更新 更多