34 #include <QVBoxLayout>
35 #include <QHBoxLayout>
37 #include <QtCore/QDebug>
41 m_vertical(isVertical),
42 m_iconAbove(iconAbove)
44 m_listWidget =
new QListWidget(
this);
45 m_stackWidget =
new QStackedWidget();
46 m_stackWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
48 QBoxLayout *toplevelLayout;
50 toplevelLayout =
new QHBoxLayout;
51 toplevelLayout->addWidget(m_listWidget);
52 toplevelLayout->addWidget(m_stackWidget);
53 m_listWidget->setFlow(QListView::TopToBottom);
54 m_listWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
55 m_listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
57 toplevelLayout =
new QVBoxLayout;
58 toplevelLayout->addWidget(m_stackWidget);
59 toplevelLayout->addWidget(m_listWidget);
60 m_listWidget->setFlow(QListView::LeftToRight);
61 m_listWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
62 m_listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
65 if (m_iconAbove && m_vertical) {
66 m_listWidget->setFixedWidth(91);
67 m_listWidget->setWrapping(
false);
69 m_listWidget->setStyleSheet(QString(
"QScrollBar:vertical { width: 6px; border-width: 0px; background: none; margin: 2px 0px 2px 0px; }"
70 "QScrollBar::handle:vertical { background: #5c5c5c; border-radius: 3px; }"
71 "QScrollBar::add-line:vertical { width: 0; height: 0; }"
72 "QScrollBar::sub-line:vertical { width: 0; height: 0 }"));
75 toplevelLayout->setSpacing(0);
76 toplevelLayout->setContentsMargins(0, 0, 0, 0);
77 m_listWidget->setContentsMargins(0, 0, 4, 0);
78 m_listWidget->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
79 m_listWidget->setSpacing(4);
80 m_listWidget->setViewMode(QListView::IconMode);
81 m_stackWidget->setContentsMargins(0, 0, 0, 0);
82 setLayout(toplevelLayout);
84 connect(m_listWidget, SIGNAL(currentRowChanged(
int)),
this, SLOT(showWidget(
int)),Qt::QueuedConnection);
89 tab->setContentsMargins(0, 0, 0, 0);
90 m_stackWidget->insertWidget(index, tab);
91 QListWidgetItem *item =
new QListWidgetItem(icon, label);
92 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
93 item->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom);
94 item->setToolTip(label);
97 item->setSizeHint(QSize(85, 82));
100 m_listWidget->insertItem(index, item);
105 QWidget * wid=m_stackWidget->widget(index);
106 m_stackWidget->removeWidget(wid);
108 QListWidgetItem *item = m_listWidget->item(index);
109 m_listWidget->removeItemWidget(item);
115 return m_listWidget->currentRow();
120 m_listWidget->setCurrentRow(index);
123 void MyTabbedStackWidget::showWidget(
int index)
125 if(m_stackWidget->currentIndex()==index)
131 m_stackWidget->setCurrentIndex(index);
136 m_listWidget->setCurrentRow(m_stackWidget->currentIndex(),QItemSelectionModel::ClearAndSelect);
149 QListWidgetItem *
i = m_listWidget->item(index);