mobile - 选项卡 QML 中的图标

标签 mobile tabs qml tabview

我正在查找 QML 文档,但没有找到:

  • 有没有办法将图像插入到 QML 中 TabViewTab 中?
  • 是否可以滚动选项卡

最佳答案

@folibis 是对的,但在他的允许下,我想向您展示一个示例,因为可能很难理解如何在 QML 选项卡中设置图像。

import QtQuick 2.2
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

Window {
    id: window
    width: 640
    height: 480
    visible: true
    title: qsTr("Example")


    TabView {
        anchors.fill: parent

        Tab { title: "One" ; Item {}}
        Tab { title: "Two" ; Item {}}
        Tab { title: "Three" ; Item {}}
        Tab { title: "Four" ; Item {}}
        style: tabViewStyle
    }

    Component {
        id: tabViewStyle
        TabViewStyle {
            tabsMovable: true

            tab: Item {
                implicitWidth: 97
                implicitHeight: 28

                Image {
                    id: image
                    anchors.centerIn: parent
                    source: styleData.selected ? "images/tab_selected.png" : "images/tab.png"
                }
                Text {
                    id: text
                    text: styleData.selected ? "" : styleData.title
                    anchors.horizontalCenter: parent.horizontalCenter
                }
            }

            frame: Rectangle { color: "steelblue" }
        }
    }
}

uploaded将代码发送到 GitHub。

已更新

您可以根据您的要求使用一些TabViewStyle属性来加载不同的图像。 IE。下一个代码是使用 int styleData.index 加载不同的源。代码也在 GitHub 中。

        TabViewStyle {
            tabsMovable: true

            tab: Item {
                function loadImage(index) {
                    return "images/tab"+index+".png";
                }

                implicitWidth: 97
                implicitHeight: 28

                Image {
                    id: image
                    anchors.centerIn: parent                        
                    source: loadImage(styleData.index)
                }
                Text {
                    id: text
                    text: styleData.selected ? "" : styleData.title
                    anchors.horizontalCenter: parent.horizontalCenter
                }
            }

            frame: Rectangle { color: "steelblue" }
        }

关于mobile - 选项卡 QML 中的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33376467/

相关文章:

android - 设置 ActionBar 选项卡的样式

javascript - 使用 jquery 更改选项卡标题?

css - Bootstrap v2.3.1 不适用于选项卡

qt - 将 QML PathView 限制为 1 次索引滑动

javascript - 如果存在视口(viewport),为什么 jQuery 动画无法在移动设备上运行?

2009 年智能手机支持 AJAX

mobile - 如何确保 http 请求不是手工制作的?

php - 如何确定设备是移动设备还是桌面设备?

python - 为什么PySide2中我的QVideoFilterRunnable的 "run()"方法没有被执行?

c++ - QML 中属性绑定(bind)评估的顺序和方式