Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. tabview with dynamic tabs
Qt 6.11 is out! See what's new in the release blog

tabview with dynamic tabs

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 503 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    satyanarayana143
    wrote on last edited by
    #1

    Hi friends,

    I am trying to create tabview with tabs like browser in qml.I have written below code

    import QtQuick 2.0
    import QtQuick 2.2
    import QtQuick.Controls 1.1
    import QtQuick.Layouts 1.1
    import QtQuick.Controls 2.2
    import QtQuick.Controls 2.15
    import QtQuick 2.5
    import QtQuick.Window 2.2
    import QtQuick.Dialogs 1.3
    import QtQuick.Controls.Styles 1.1
    import QtQuick.Controls 1.2

    Rectangle
    {
    id:tabViewgui
    color: "gray"
    border.color: "black"
    border.width: 5
    radius: 8
    visible: true

    Dialog
    {
        id: errorDialog
        title: "Yazmi"
        width: 300
    
        ColumnLayout
        {
            Label
            {
                text: qsTr("More than 10 tabs cannot be created.")
                font.pixelSize: 15
            }
    
        }
        standardButtons: StandardButton.Ok
    }
    
    
    TabView
    {
        id: tabView
        anchors.margins: 2
        visible: false
        anchors.fill: parent
        style: TabViewStyle
        {
            property color frameColor: "#484848"
            property color fillColor: "#484848"
    
            tab: Rectangle
            {
                color: styleData.selected ? fillColor : frameColor
                implicitWidth: Math.max(text.width + 45, 80)
                implicitHeight: 35
                border.color: "black"
                border.width:1.5
                radius: 8
    
                Text
                {
                    id: text
                    anchors.left: parent.left
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.leftMargin: 6
                    text: styleData.title
                    color: styleData.selected ? "white" : "white"
                    font.pixelSize: 15
    
                }
                ToolButton
                {
                    anchors.right: parent.right
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.rightMargin: 4
                    implicitWidth: 30
                    implicitHeight: 30
                    iconSource: "qrc:/images/close2.png"
    
                    onClicked:
                    {
                        onClicked: tabView.removeTab(styleData.index)
                        addbutn.x = (addbutn.x - tabView.implicitWidth/2)
                    }
                }
    
    
            }
    
        }
    }
    ToolButton
    {
        id:addbutn
        iconSource: "qrc:/images/Add2.png"
        antialiasing: true
        x:0
        y:0
        //anchors.fill:parent
        onClicked:
        {
            console.log("addbutn clicked")
    
            tabView.visible = true
            if(tabView.count < 10)
            {
                var c = Qt.createComponent("Paintview.qml");
                tabView.addTab("WhiteBoard",c);
                var last = tabView.count-1;
                tabView.getTab(last).active = true; // Now the content will be loaded
                addbutn.x = tabView.count*(tabView.implicitWidth/2)
                console.log("addbutn X Position :",addbutn.x,anchors.leftMargin,tabView.count)
            }
            else
            {
                errorDialog.open()
            }
    
        }
    }
    

    }

    In this when in click on ToolButton it is not working.
    when i enable this line in code //anchors.fill:parent
    it is working but I cannot put x and y pos to zero.
    Can anybody tell problem and how to solve.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved