PDA

View Full Version : tab widget with two entries



acmezger
28th March 2013, 09:36
hello,

I am looking for a widget similar to the tabwidget; however it should be a container with tabs on the left and on the top in order to be able to select widgets according to two entries instaed of one entry like the tabwidget.

This would be used to select something according two criteria.

Does someone has an idea to do this ?

Thanks

Santosh Reddy
28th March 2013, 09:45
Can you use this ways.... put a QTabWidget (with left tabs) as a page in another QTabWidget (with top tabs). So will be like the top level QTabWidget (top tabs) will have multiple QTabWidgets (left tabs) as pages. :)

acmezger
28th March 2013, 10:14
Yes, thats what I did, however for many double entries this is quite a work. I hoped it would be easier
Thanks

Santosh Reddy
28th March 2013, 12:48
You could write such widget with help of two QTabBars and a QStackedWidget, here is a working example for it.



#include <QtGui>
#include <QApplication>

class DoubleTabWidget : public QWidget
{
Q_OBJECT

public:
explicit DoubleTabWidget(DoubleTabWidget * parent = 0)
: QWidget(parent)
, row(0)
, col(0)
, hTabBar(new QTabBar)
, vTabBar(new QTabBar)
, viewPort(new QStackedWidget)
{
QGridLayout * gridLayout = new QGridLayout(this);

gridLayout->addWidget(hTabBar, 0, 1, 1, 1);
gridLayout->addWidget(vTabBar, 1, 0, 1, 1);
gridLayout->addWidget(viewPort, 1, 1, 1, 1);

hTabBar->setShape(QTabBar::RoundedNorth);
vTabBar->setShape(QTabBar::RoundedWest);

connect(vTabBar, SIGNAL(currentChanged(int)), SLOT(setRow(int)));
connect(hTabBar, SIGNAL(currentChanged(int)), SLOT(setCol(int)));

addSampleWidget();
}

private slots:
void setRow(int r)
{
row = r;
updateWidget();
}

void setCol(int c)
{
col = c;
updateWidget();
}

private:
int row;
int col;
QTabBar * hTabBar;
QTabBar * vTabBar;
QStackedWidget * viewPort;
QList<QList<QWidget *> > widgets;

void updateWidget(void)
{
if(col < widgets.count())
if(row < widgets.at(col).count())
viewPort->setCurrentWidget(widgets.at(col).at(row));
}

QWidget * createWidget(int r, int c)
{
const QString name = QString("QWidget (%1, %2)").arg(r).arg(c);

QWidget * widget = new QGroupBox;
QGridLayout * gridLayout = new QGridLayout;
QWidget * label = new QLabel(name);
gridLayout->addWidget(label);
gridLayout->setAlignment(label, Qt::AlignCenter);
widget->setLayout(gridLayout);
return widget;
}

void addSampleWidget(void)
{
QList<QWidget *> wids;

for(int i = 0; i < 5; i++)
hTabBar->addTab(QString("Widget %1").arg(i));

for(int j = 0; j < 5; j++)
vTabBar->addTab(QString("Widget %1").arg(j));

for(int i = 0; i < 5; i++)
{
wids.clear();
for(int j = 0; j < 5; j++)
{
QWidget * widget = createWidget(i, j);
wids.append(widget);
viewPort->addWidget(widget);
}
widgets.append(wids);
}
}
};

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

DoubleTabWidget tabWidget;
tabWidget.show();

return app.exec();
}

#include "main.moc"

acmezger
28th March 2013, 14:56
yust what I was looking for, many thanks. I will put this widget into the designer.

that was a great help

Added after 35 minutes:

works fine in designer too, but how would you have the viewport populated in designer by dropping objects on it?

acmezger
29th March 2013, 10:21
In designer I would like to have this widget act as a container for every item choosen like the normat tabwidget, however now with two entries (multipage)

acmezger
1st April 2013, 13:08
I already made some plugins that work fine. my problem is just how to set up the multipage container for the widget