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"
}
}
}
}
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"
}
}
}
}
To copy to clipboard, switch view to plain text mode
TabContext.h
#ifndef TABCONTEXT_H
#define TABCONTEXT_H
#pragma warning(push, 0)
#include <qobject.h>
#pragma warning(pop)
{
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
#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
To copy to clipboard, switch view to plain text mode
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();
}
}
#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();
}
}
To copy to clipboard, switch view to plain text mode
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();
}
#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();
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks