Results 1 to 7 of 7

Thread: tab widget with two entries

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2013
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: tab widget with two entries

    Yes, thats what I did, however for many double entries this is quite a work. I hoped it would be easier
    Thanks

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: tab widget with two entries

    You could write such widget with help of two QTabBars and a QStackedWidget, here is a working example for it.

    Qt Code:
    1. #include <QtGui>
    2. #include <QApplication>
    3.  
    4. class DoubleTabWidget : public QWidget
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. explicit DoubleTabWidget(DoubleTabWidget * parent = 0)
    10. : QWidget(parent)
    11. , row(0)
    12. , col(0)
    13. , hTabBar(new QTabBar)
    14. , vTabBar(new QTabBar)
    15. , viewPort(new QStackedWidget)
    16. {
    17. QGridLayout * gridLayout = new QGridLayout(this);
    18.  
    19. gridLayout->addWidget(hTabBar, 0, 1, 1, 1);
    20. gridLayout->addWidget(vTabBar, 1, 0, 1, 1);
    21. gridLayout->addWidget(viewPort, 1, 1, 1, 1);
    22.  
    23. hTabBar->setShape(QTabBar::RoundedNorth);
    24. vTabBar->setShape(QTabBar::RoundedWest);
    25.  
    26. connect(vTabBar, SIGNAL(currentChanged(int)), SLOT(setRow(int)));
    27. connect(hTabBar, SIGNAL(currentChanged(int)), SLOT(setCol(int)));
    28.  
    29. addSampleWidget();
    30. }
    31.  
    32. private slots:
    33. void setRow(int r)
    34. {
    35. row = r;
    36. updateWidget();
    37. }
    38.  
    39. void setCol(int c)
    40. {
    41. col = c;
    42. updateWidget();
    43. }
    44.  
    45. private:
    46. int row;
    47. int col;
    48. QTabBar * hTabBar;
    49. QTabBar * vTabBar;
    50. QStackedWidget * viewPort;
    51. QList<QList<QWidget *> > widgets;
    52.  
    53. void updateWidget(void)
    54. {
    55. if(col < widgets.count())
    56. if(row < widgets.at(col).count())
    57. viewPort->setCurrentWidget(widgets.at(col).at(row));
    58. }
    59.  
    60. QWidget * createWidget(int r, int c)
    61. {
    62. const QString name = QString("QWidget (%1, %2)").arg(r).arg(c);
    63.  
    64. QWidget * widget = new QGroupBox;
    65. QGridLayout * gridLayout = new QGridLayout;
    66. QWidget * label = new QLabel(name);
    67. gridLayout->addWidget(label);
    68. gridLayout->setAlignment(label, Qt::AlignCenter);
    69. widget->setLayout(gridLayout);
    70. return widget;
    71. }
    72.  
    73. void addSampleWidget(void)
    74. {
    75. QList<QWidget *> wids;
    76.  
    77. for(int i = 0; i < 5; i++)
    78. hTabBar->addTab(QString("Widget %1").arg(i));
    79.  
    80. for(int j = 0; j < 5; j++)
    81. vTabBar->addTab(QString("Widget %1").arg(j));
    82.  
    83. for(int i = 0; i < 5; i++)
    84. {
    85. wids.clear();
    86. for(int j = 0; j < 5; j++)
    87. {
    88. QWidget * widget = createWidget(i, j);
    89. wids.append(widget);
    90. viewPort->addWidget(widget);
    91. }
    92. widgets.append(wids);
    93. }
    94. }
    95. };
    96.  
    97. int main(int argc, char *argv[])
    98. {
    99. QApplication app(argc, argv);
    100.  
    101. DoubleTabWidget tabWidget;
    102. tabWidget.show();
    103.  
    104. return app.exec();
    105. }
    106.  
    107. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. How to read registry entries
    By Abc in forum Qt Programming
    Replies: 16
    Last Post: 22nd August 2008, 08:53
  2. Qt4.1.1: Sorting QCombobox entries
    By Byngl in forum Qt Programming
    Replies: 4
    Last Post: 17th March 2006, 09:02
  3. Replies: 4
    Last Post: 9th March 2006, 23:22

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.