本文整理汇总了C++中QListWidget::findItems方法的典型用法代码示例。如果您正苦于以下问题:C++ QListWidget::findItems方法的具体用法?C++ QListWidget::findItems怎么用?C++ QListWidget::findItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QListWidget
的用法示例。
在下文中一共展示了QListWidget::findItems方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setEditorData
void OperationsDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
const QVariant value = index.data(Qt::EditRole);
if (value.type() == QVariant::StringList) {
QListWidget *lw = qobject_cast<QListWidget *>(editor);
const auto items = lw->findItems(index.data(Qt::DisplayRole).toString(), Qt::MatchExactly);
if (!items.empty())
lw->setCurrentItem(items.first());
else
lw->setCurrentItem(lw->item(0));
const int extraWidth = 25;
const int extraHeight = 6;
lw->setMinimumWidth(lw->sizeHintForColumn(0) + extraWidth);
// to prevent possible hiding bottom part of the list
const int h = lw->count() * (lw->visualItemRect(lw->currentItem()).height() + extraHeight);
const int y = (lw->parentWidget() && (lw->parentWidget()->rect().bottom() < lw->y() + h))
? lw->parentWidget()->rect().bottom() - h - extraHeight : lw->y();
lw->setGeometry(lw->x(), y, lw->width(), h);
// now lw can be partially hidden behind the tree view
// if tree view has small rect, so set parent of lw
// to app window and map coordinates accordingly to leave lw in place
const auto globalCoord = lw->parentWidget()->mapToGlobal(lw->geometry().topLeft());
lw->setParent(appWindow);
const auto newLocalCoord = appWindow->mapFromGlobal(globalCoord);
lw->setGeometry(newLocalCoord.x(), newLocalCoord.y(), lw->width(), h);
}
else // single value
QStyledItemDelegate::setEditorData(editor, index);
}
示例2: str
dmz::V8Value
dmz::JsModuleUiV8QtBasic::_list_widget_find_items (const v8::Arguments &Args) {
v8::HandleScope scope;
V8Value result = v8::Undefined ();
JsModuleUiV8QtBasic *self = _to_self (Args);
if (self) {
QListWidget *table = self->v8_to_qobject<QListWidget> (Args.This ());
if (table) {
if (Args.Length ()) {
QString str (v8_to_qstring (Args[0]));
Qt::MatchFlags flag = Qt::MatchExactly;
if (Args.Length () > 1) {
flag = (Qt::MatchFlags)v8_to_uint32 (Args[1]);
}
QList<QListWidgetItem *> items = table->findItems (str, flag);
const int Length = items.count ();
V8Array array = v8::Array::New (Length);
for (int ix = 0; ix < Length; ++ix) {
V8Value value = self->create_v8_qlistwidgetitem (items.at (ix));
array->Set (v8::Integer::New (ix), value);
}
result = array;
}
}
}
return scope.Close (result);
}
示例3: onLabelRemoved
void MainWindow::onLabelRemoved(medusa::Label const & label)
{
QString labelName = QString::fromStdString(label.GetName());
QListWidget *curList = nullptr;
switch (label.GetType())
{
case medusa::Label::LabelData: curList = dataList; break;
case medusa::Label::LabelCode: curList = codeList; break;
case medusa::Label::LabelString: curList = stringList; break;
default: break;
}
if (curList != nullptr)
{
auto items = curList->findItems(labelName, Qt::MatchExactly);
// something bad happened
if (items.size() != 1) return;
auto item = items.takeFirst();
curList->removeItemWidget(item);
delete item;
}
if (label.GetType() & medusa::Label::LabelImported)
curList = importedList;
else if (label.GetType() & medusa::Label::LabelExported)
curList = exportedList;
if (curList != nullptr)
{
auto items = curList->findItems(labelName, Qt::MatchExactly);
// something bad happened
if (items.size() != 1) return;
auto item = items.takeFirst();
curList->removeItemWidget(item);
delete item;
}
}