Results 1 to 2 of 2

Thread: TabView issue

  1. #1
    Join Date
    Sep 2013
    Posts
    9
    Thanked 1 Time in 1 Post

    Default TabView issue

    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:
    NormalTab.png
    Bad:
    WrongTab.png

    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

  2. #2
    Join Date
    Sep 2013
    Posts
    9
    Thanked 1 Time in 1 Post

    Default Re: TabView issue

    I've got a more simple case to show the error:

    Main.qml:
    Qt Code:
    1. import QtQuick 2.0
    2. import QtQuick.Layouts 1.0
    3. import QtQuick.Controls 1.0
    4.  
    5. Rectangle {
    6. width: 800
    7. height: 600
    8. color: "red"
    9.  
    10. TabView
    11. {
    12. id: operatorTabs
    13.  
    14. anchors.left: parent.left;
    15. anchors.leftMargin: 5;
    16. anchors.top: parent.top;
    17. anchors.topMargin: 5;
    18.  
    19. width: parent.width - 10;
    20. height: parent.height - 10;
    21.  
    22. currentIndex: tabContext.tabIndex;
    23. Binding
    24. {
    25. target: tabContext;
    26. property: "tabIndex";
    27. value: operatorTabs.currentIndex;
    28. }
    29. Tab
    30. {
    31. title: "Jobs";
    32. Rectangle
    33. {
    34. anchors.fill: parent
    35. color: "green"
    36. }
    37. }
    38. Tab
    39. {
    40. title: "System Monitor";
    41. Rectangle
    42. {
    43. anchors.fill: parent
    44. color: "yellow"
    45. }
    46. }
    47. Tab
    48. {
    49. title: "History";
    50. Rectangle
    51. {
    52. anchors.fill: parent
    53. color: "blue"
    54. }
    55. }
    56. }
    57. }
    To copy to clipboard, switch view to plain text mode 
    TabContext.h
    Qt Code:
    1. #ifndef TABCONTEXT_H
    2. #define TABCONTEXT_H
    3.  
    4. #pragma warning(push, 0)
    5. #include <qobject.h>
    6. #pragma warning(pop)
    7.  
    8.  
    9. class TabContext : public QObject
    10. {
    11. Q_OBJECT
    12. Q_PROPERTY(int tabIndex READ getTabIndex WRITE setTabIndex NOTIFY tabIndexChanged);
    13.  
    14. public:
    15. TabContext ();
    16. virtual ~TabContext (void);
    17.  
    18. public:
    19. int getTabIndex () const;
    20. void setTabIndex (int index);
    21.  
    22.  
    23. signals:
    24. void tabIndexChanged ();
    25.  
    26. private:
    27. int _tabIndex;
    28. };
    29.  
    30. #endif
    To copy to clipboard, switch view to plain text mode 

    TabContext.cpp
    Qt Code:
    1. #include "TabContext.h"
    2.  
    3.  
    4. TabContext::TabContext(void)
    5. : _tabIndex(0)
    6. {
    7. }
    8.  
    9.  
    10. TabContext::~TabContext(void)
    11. {
    12. }
    13.  
    14.  
    15. int TabContext::getTabIndex() const
    16. {
    17. return _tabIndex;
    18. }
    19.  
    20. void TabContext::setTabIndex(int index)
    21. {
    22. if(index != _tabIndex)
    23. {
    24. _tabIndex = index;
    25. emit tabIndexChanged();
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 
    Main.cpp
    Qt Code:
    1. #pragma warning(push, 0)
    2. #include "qtquick2applicationviewer.h"
    3. #pragma warning(pop)
    4.  
    5. #include "TabContext.h"
    6.  
    7. #pragma warning(push, 0)
    8. #include <QtGui/QGuiApplication>
    9. #include <QtQml/qqmlcontext.h>
    10. #pragma warning(pop)
    11. #pragma warning(push, 0)
    12. #include <qobject.h>
    13. #include <qstringlist.h>
    14. #pragma warning(pop)
    15.  
    16.  
    17. #include "qtquick2applicationviewer.h"
    18.  
    19. int main(int argc, char *argv[])
    20. {
    21. QGuiApplication app(argc, argv);
    22.  
    23. QtQuick2ApplicationViewer viewer;
    24. TabContext context;
    25.  
    26. viewer.rootContext()->setContextProperty(QString("tabContext"), &context);
    27.  
    28. viewer.setMainQmlFile(QStringLiteral("qml/test/main.qml"));
    29. viewer.showExpanded();
    30.  
    31. return app.exec();
    32. }
    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

Similar Threads

  1. VNC Issue!
    By sanujas in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 24th October 2013, 07:22
  2. Qt 5.0.1 Issue
    By kiboi in forum Qt-based Software
    Replies: 0
    Last Post: 22nd March 2013, 05:22
  3. XML issue
    By jbpvr in forum Qt Programming
    Replies: 1
    Last Post: 25th August 2008, 13:01
  4. UI issue.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2008, 11:41
  5. qt3 to qt4 - uic issue
    By hvengel in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2007, 02:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.