listview没有出现在TabGroup QML中?

时间:2012-03-07 13:00:10

标签: qt listview tabs qml

如何在QML中显示列表视图显示在选项卡中。我在N9(Meego)的应用程序中使用代码,但现在我需要在Symbian中使用它。当我将它从meego转换为symbian时,我做了一些更改,但没有列表视图出现。请帮忙。 注意:当我不使用标签时,会出现相同的列表视图!!!

我的代码:

import QtQuick 1.1
import com.nokia.symbian 1.1
import com.nokia.extras 1.1
import "UIConstants.js" as UiConstants

Page {
  id: mainpage

       orientationLock: PageOrientation.LockPortrait



    tools:
    TabBar {
           // platformStyle: TabButtonStyle { }
            TabButton {
           text: "Tab 1"
                tab: tab1

            }
            TabButton {
                text: "Tab 2"

                tab: tab2

            }
            TabButton {
                text: "Tab 3"
                tab: tab3

            }
            TabButton {
               text: "Tab 4"
                tab: tab4

            }
                       }



    TabGroup {
             id: tabGroup

             PageStack {
                id: tab1
                Component.onCompleted: tab1.push(listPage)

             // define the content for tab 1
             Page {
                 id: listPage


                   Item {
                             id: testList
                            anchors.fill: parent

                              function openFile(file) {
                                 var component = Qt.createComponent(file)

                                 if (component.status == Component.Ready) {
                                     mainWindow.pageStack.push(component);
                                     console.log("Loading component okay");
                                 }
                                 else {
              console.log("Error loading component:", component.errorString());
                                 }
                             }

                             ListModel {
                                 id: pagesModel

                                 ListElement {
                                     page: "InfoBannerPage.qml"
                                     title: "InfoBanner"
                                     subtitle: "Info Banner"
                                 }

                                 ListElement {
                                     page: "RatingIndicator.qml"
                                     title: "RatingIndicator"
                                     subtitle: "Indicates ratings"
                                 }

                             }

                             ListView {
                                 id: list
                                 model: pagesModel
                                 anchors.fill: parent

                                 delegate: ListItem {
                                     id: listItem

                                     platformInverted: mainWindow.childrenInverted

                                     Row {
                                         id: listItemRow


                                         Column {

                                             ListItemText {
                                                 id: mainText
                                               //  width: listItemRow.width
                                                 role: "Title"
                                                 text: title

                                             }

                                             ListItemText {
                                                 id: subText
                                             //   width: listItemRow.width
                                                 role: "SubTitle"
                                                 text: subtitle
                                                 visible: text != ""

                                             }
                                         }
                                     }

                                     onClicked: { testList.openFile(page); }
                                 } // listItem
                             } // listView

                             ScrollDecorator {
                                 flickableItem: listPage
                                 platformInverted: mainWindow.childrenInverted
                             }
                         } // item
                     } // page
   }



             Page {
                 id: tab2

             }
             Page {
                 id: tab3

             }
             Page {
            id: tab4

        }

    }

}

1 个答案:

答案 0 :(得分:0)

您的布局存在问题。

工作一:

import QtQuick 1.1
import com.nokia.symbian 1.1
import com.nokia.extras 1.1

Page {
  id: mainpage

       orientationLock: PageOrientation.LockPortrait



//    tools:
    TabBar {
        id: tabBar
        anchors {top: parent.top }
           // platformStyle: TabButtonStyle { }
            TabButton {
           text: "Tab 1"
                tab: tab1

            }
            TabButton {
                text: "Tab 2"

                tab: tab2

            }
            TabButton {
                text: "Tab 3"
                tab: tab3

            }
            TabButton {
               text: "Tab 4"
                tab: tab4

            }
                       }



    TabGroup {
             id: tabGroup
             anchors {top: tabBar.bottom; bottom: parent.bottom}

             PageStack {
                id: tab1
                Component.onCompleted: tab1.push(listPage)

             // define the content for tab 1
             Page {
                 id: listPage
                 anchors.fill: parent


                   Item {
                             id: testList
                            anchors.fill: parent

                              function openFile(file) {
                                 var component = Qt.createComponent(file)

                                 if (component.status == Component.Ready) {
                                     mainWindow.pageStack.push(component);
                                     console.log("Loading component okay");
                                 }
                                 else {
              console.log("Error loading component:", component.errorString());
                                 }
                             }

                             ListModel {
                                 id: pagesModel

                                 ListElement {
                                     page: "InfoBannerPage.qml"
                                     title: "InfoBanner"
                                     subtitle: "Info Banner"
                                 }

                                 ListElement {
                                     page: "RatingIndicator.qml"
                                     title: "RatingIndicator"
                                     subtitle: "Indicates ratings"
                                 }

                             }

                             ListView {
                                 id: list
                                 model: pagesModel
                                 anchors.fill: parent

                                 delegate: ListItem {
                                     id: listItem

//                                     platformInverted: mainWindow.childrenInverted

                                     Row {
                                         id: listItemRow
                                         anchors.fill: listItem.paddingItem


                                         Column {

                                             ListItemText {
                                                 id: mainText
                                               //  width: listItemRow.width
                                                 role: "Title"
                                                 text: title

                                             }

                                             ListItemText {
                                                 id: subText
                                             //   width: listItemRow.width
                                                 role: "SubTitle"
                                                 text: subtitle
                                                 visible: text != ""

                                             }
                                         }
                                     }

                                     onClicked: { testList.openFile(page); }
                                 } // listItem
                             } // listView

                             ScrollDecorator {
//                                 flickableItem: listPage
//                                 platformInverted: mainWindow.childrenInverted
                             }
                         } // item
                     } // page
   }



             Page {
                 id: tab2

             }
             Page {
                 id: tab3

             }
             Page {
            id: tab4

        }

    }
}