PDA

View Full Version : QML: a SwipeView inside a Rectangle



mentalmushroom
30th January 2017, 10:17
I've been trying to place a SwipeView with two pages inside a Rectangle and indent it by 20 pixels from each side:



import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0

ApplicationWindow
{
visible: true
width: 640
height: 480
title: qsTr("Hello World")

Column
{
anchors.fill: parent
//anchors.margins: 20

Rectangle
{
id: yellowRect
color: "yellow"
width: parent.width
height: parent.height - tabBar.height
//anchors.fill: parent
//anchors.margins: 20

SwipeView
{
id: swipeView
//parent: yellowRect
//anchors.fill: yellowRect//parent
anchors.margins: 20
anchors.fill: parent
currentIndex: tabBar.currentIndex

Page
{
//width: 300
//height: 300
//anchors.fill: parent
//anchors.margins: 20
Column
{
Label { text: "First page" }
TextField { }
}
}

Page
{
//anchors.fill: parent
//anchors.margins: 20
//width: 300
//height: 300
Label {
text: qsTr("Second page")
anchors.centerIn: parent
}
}
} // Swipeview
} // Rectangle

TabBar
{
id: tabBar
TabButton { text: "First" }
TabButton { text: "Second" }
}
} // Column
} // ApplicationWindow


The code above produces the following:
12315
12316

In particular, there is no indent on the right when the first page is active or the left when the second page is active.

How can I fix that?

anda_skoa
31st January 2017, 08:59
That could be the pages being drawn outside the parent.

You could check by enabling clipping on the parent/view.

Cheers,
_