50 setEditTriggers(QAbstractItemView::NoEditTriggers);
55 setFrameShape(QFrame::StyledPanel);
56 setFrameShadow(QFrame::Raised);
63 setMinimumHeight(300);
65 verticalScrollBar()->setPageStep(3);
66 verticalScrollBar()->setSingleStep(1);
68 model_ =
new QStandardItemModel(
this);
77 for (
int i = 0; i < navs.size(); i++)
79 QStandardItem* item =
new QStandardItem();
80 item->setData(QVariant::fromValue(navs.at(i)), Qt::DisplayRole);
81 item->setFlags(Qt::NoItemFlags);
91 model_->item(index)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled |
92 Qt::ItemIsDropEnabled | Qt::ItemIsEnabled);
94 model_->item(index)->setFlags(Qt::NoItemFlags);
103 QModelIndex top =
model_->index(index, 0, QModelIndex());
104 QModelIndex bottom =
model_->index(index, 0, QModelIndex());
106 QItemSelection selection(top, bottom);
107 selectionModel()->reset();
108 selectionModel()->select(selection, QItemSelectionModel::Select);
121 return QSize(option.rect.width(), 45);
124 void NavDelegate::paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index)
const 126 const bool isSelected = option.state & QStyle::State_Selected;
129 QString nav_name = index.data().value<QString>();
133 QLinearGradient backgroundGradient(QPoint(option.rect.x(), option.rect.y()),
134 QPoint(option.rect.x(), option.rect.y() + option.rect.height()));
137 backgroundGradient.setColorAt(0, QColor(109, 164, 219));
138 backgroundGradient.setColorAt(1, QColor(61, 138, 212));
139 painter->fillRect(option.rect, QBrush(backgroundGradient));
143 backgroundGradient.setColorAt(0, QColor(245, 245, 245));
144 backgroundGradient.setColorAt(1, QColor(240, 240, 240));
145 painter->fillRect(option.rect, QBrush(backgroundGradient));
148 painter->setPen(QColor(225, 225, 225));
151 painter->setPen(QColor(37, 105, 169));
152 painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
153 painter->setPen(Qt::transparent);
155 painter->drawLine(option.rect.topLeft(), option.rect.topRight());
158 painter->setPen(QColor(248, 248, 248));
159 painter->drawLine(QPoint(option.rect.x(), option.rect.y() + 1),
160 QPoint(option.rect.x() + option.rect.width(), option.rect.y() + 1));
163 QRect textRect(option.rect.x() + 10, option.rect.y(), option.rect.width() - 10, option.rect.height());
165 QFont textFont(painter->font());
166 textFont.setPixelSize(14);
167 painter->setFont(textFont);
173 painter->setPen(QColor(229, 229, 229));
175 else if (index.flags().testFlag(Qt::NoItemFlags))
178 painter->setPen(QColor(170, 170, 170));
183 painter->setPen(QColor(69, 69, 69));
186 painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, nav_name);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
NavDelegate(QObject *parent=0)