So i have decided to create my own simple "stacked widget" and it seems to work fine. For anyone interested:
Definition:
#include <QList>
#include <QWidget>
class StackedWidget
: public QWidget {
Q_OBJECT
public:
StackedWidget
(QWidget * = 0, Qt
::WindowFlags = 0);
int count();
void setAutoResize(bool yes)
{ auto_resize = yes; }
protected:
void showCurrentWidget();
private:
bool auto_resize;
int curr_index;
QList<QWidget *> widgets;
public slots:
void setCurrentIndex(int);
};
#include <QList>
#include <QWidget>
class StackedWidget : public QWidget
{
Q_OBJECT
public:
StackedWidget(QWidget * = 0, Qt::WindowFlags = 0);
void addWidget(QWidget *);
int count();
QWidget * currentWidget();
void setAutoResize(bool yes)
{ auto_resize = yes; }
QSize sizeHint();
protected:
void showCurrentWidget();
private:
bool auto_resize;
int curr_index;
QList<QWidget *> widgets;
public slots:
void setCurrentIndex(int);
};
To copy to clipboard, switch view to plain text mode
Implementation:
#include <QVBoxLayout>
StackedWidget
::StackedWidget(QWidget * parent, Qt
::WindowFlags f
) curr_index(0)
{
}
int StackedWidget::count()
{ return widgets.count(); }
void StackedWidget
::addWidget(QWidget * w
) {
widgets.append(w);
layout()->addWidget(w);
showCurrentWidget();
}
QWidget * StackedWidget
::currentWidget() { return widgets.at(curr_index); }
void StackedWidget::setCurrentIndex(int i)
{
curr_index = i;
showCurrentWidget();
}
void StackedWidget::showCurrentWidget()
{
if (widgets.count() > 0)
{
foreach
(QWidget * widget, widgets
) widget->hide();
widgets.at(curr_index)->show();
updateGeometry();
}
}
QSize StackedWidget
::sizeHint() {
if (auto_resize
&& count() > 0)
return currentWidget()->minimumSize();
else
}
#include <QVBoxLayout>
StackedWidget::StackedWidget(QWidget * parent, Qt::WindowFlags f)
: QWidget(parent, f),
curr_index(0)
{
QVBoxLayout * layout = new QVBoxLayout(this);
}
int StackedWidget::count()
{ return widgets.count(); }
void StackedWidget::addWidget(QWidget * w)
{
widgets.append(w);
layout()->addWidget(w);
showCurrentWidget();
}
QWidget * StackedWidget::currentWidget()
{ return widgets.at(curr_index); }
void StackedWidget::setCurrentIndex(int i)
{
curr_index = i;
showCurrentWidget();
}
void StackedWidget::showCurrentWidget()
{
if (widgets.count() > 0)
{
foreach (QWidget * widget, widgets)
widget->hide();
widgets.at(curr_index)->show();
updateGeometry();
}
}
QSize StackedWidget::sizeHint()
{
if (auto_resize
&& count() > 0)
return currentWidget()->minimumSize();
else
return QWidget::sizeHint();
}
To copy to clipboard, switch view to plain text mode
Bookmarks