PDA

View Full Version : TabView issue



MattieB
2nd April 2014, 08:49
Hi,

In my application i have a main.qml file which has a loader which loads the content on the screen dependent on which state the application is in.
One of the states is a TabView with 3 tabs. From the 3rd tab I can switch to a new state and from this state I can switch back to the 'tabview' state.
When I switch back from this new state to the tabview state, I want my tabview to have the third tab active. I did this by binding the currentIndex of the TabView component to a variable in my state object (which is a QObject). This seems to work, except that the rendering of the tabview is kinda messed up after I switch back: the third tab is shown as the active tab, but it seems like the content of this tab is moved up until the top anchor point of the tab(instead of the bottom anchor point). Also the border is drawn to high.
Good:
10229
Bad:
10230

Anyone has an idea what is wrong? (If i don't bind the currentIndex property, the first tab is active and it's content is shown correct (anchored to the bottom of the tab))
Regards,

Matt

MattieB
7th April 2014, 08:52
I've got a more simple case to show the error:

Main.qml:


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

Rectangle {
width: 800
height: 600
color: "red"

TabView
{
id: operatorTabs

anchors.left: parent.left;
anchors.leftMargin: 5;
anchors.top: parent.top;
anchors.topMargin: 5;

width: parent.width - 10;
height: parent.height - 10;

currentIndex: tabContext.tabIndex;
Binding
{
target: tabContext;
property: "tabIndex";
value: operatorTabs.currentIndex;
}
Tab
{
title: "Jobs";
Rectangle
{
anchors.fill: parent
color: "green"
}
}
Tab
{
title: "System Monitor";
Rectangle
{
anchors.fill: parent
color: "yellow"
}
}
Tab
{
title: "History";
Rectangle
{
anchors.fill: parent
color: "blue"
}
}
}
}

TabContext.h


#ifndef TABCONTEXT_H
#define TABCONTEXT_H

#pragma warning(push, 0)
#include <qobject.h>
#pragma warning(pop)


class TabContext : public QObject
{
Q_OBJECT
Q_PROPERTY(int tabIndex READ getTabIndex WRITE setTabIndex NOTIFY tabIndexChanged);

public:
TabContext ();
virtual ~TabContext (void);

public:
int getTabIndex () const;
void setTabIndex (int index);


signals:
void tabIndexChanged ();

private:
int _tabIndex;
};

#endif


TabContext.cpp


#include "TabContext.h"


TabContext::TabContext(void)
: _tabIndex(0)
{
}


TabContext::~TabContext(void)
{
}


int TabContext::getTabIndex() const
{
return _tabIndex;
}

void TabContext::setTabIndex(int index)
{
if(index != _tabIndex)
{
_tabIndex = index;
emit tabIndexChanged();
}
}

Main.cpp


#pragma warning(push, 0)
#include "qtquick2applicationviewer.h"
#pragma warning(pop)

#include "TabContext.h"

#pragma warning(push, 0)
#include <QtGui/QGuiApplication>
#include <QtQml/qqmlcontext.h>
#pragma warning(pop)
#pragma warning(push, 0)
#include <qobject.h>
#include <qstringlist.h>
#pragma warning(pop)


#include "qtquick2applicationviewer.h"

int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);

QtQuick2ApplicationViewer viewer;
TabContext context;

viewer.rootContext()->setContextProperty(QString("tabContext"), &context);

viewer.setMainQmlFile(QStringLiteral("qml/test/main.qml"));
viewer.showExpanded();

return app.exec();
}


If in TabContext, _tabIndex is initiallised as 0, everything is ok, if it is 1 or 2, the content from the tabs is drawn too high (the yellow and the blue square starts at the same level as the top of the tab-label, while it should start at the bottom of it).
Anybody an idea, or is it just a bug in Qt?
Regards,

Matt