本文整理汇总了C++中QListWidget::setMinimumWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ QListWidget::setMinimumWidth方法的具体用法?C++ QListWidget::setMinimumWidth怎么用?C++ QListWidget::setMinimumWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QListWidget
的用法示例。
在下文中一共展示了QListWidget::setMinimumWidth方法的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: createEditor
QWidget* MultiDelegate::createEditor( QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
const QAbstractItemModel* model = index.model();
QVariant value = model->data( index, Qt::EditRole);
switch (value.type()) {
case QMetaType::QTime:
{
QTimeEdit* editor = new QTimeEdit( parent);
editor->setMaximumWidth( editor->sizeHint().width());
//// Get value snapshot into editor
editor->setTime( value.toTime());
return editor;
}
case QMetaType::QDate:
{
QDateEdit* editor = new QDateEdit( parent);
setupCalenderWidget( editor);
editor->setMaximumWidth( editor->sizeHint().width());
//// Get value snapshot into editor
editor->setDate( value.toDate());
return editor;
}
case QMetaType::QDateTime:
{
QDateTimeEdit* editor = new QDateTimeEdit( parent);
setupCalenderWidget( editor);
editor->setMaximumWidth( editor->sizeHint().width());
editor->setDateTime( value.toDateTime());
return editor;
}
case QMetaType::QImage:
// Fall throu
case QMetaType::QPixmap:
// Fall throu
case QMetaType::QIcon:
{
PixmapViewer* editor = new PixmapViewer( parent);
connect( editor, SIGNAL(finished(int)), this, SLOT(closeEmittingEditor()));
return editor;
}
case QMetaType::QStringList:
{
QVariant varList = index.model()->data( index, ItemDataRole::EnumList);
if (varList.isNull()) break; // Not a enum-list, fall to std
QListWidget* editor = new QListWidget( parent);
foreach (const QString& bitItemText, varList.toStringList()) {
QListWidgetItem* bitItem = new QListWidgetItem( bitItemText, editor);
bitItem->setFlags(bitItem->flags() | Qt::ItemIsUserCheckable);
bitItem->setCheckState(Qt::Unchecked);
}
int width = editor->sizeHintForColumn(0) + 25;
int height = editor->sizeHintForRow(0) * editor->count() + 10;
editor->setMinimumWidth( width);
editor->setMaximumWidth( width);
editor->setMinimumHeight( height);
editor->setMaximumHeight( height);
//// Get value snapshot into editor
QStringList valList = value.toStringList();
int itemCount = editor->count();
for (int i = 0; i < itemCount; ++i) {
QListWidgetItem* bitItem = editor->item(i);
bool isActive = valList.contains( bitItem->text());
bitItem->setCheckState( isActive ? Qt::Checked : Qt::Unchecked);
}
return editor;
}
case QMetaType::QString:
{
QVariant varList = index.model()->data( index, ItemDataRole::EnumList);
if (varList.isNull()) break; // Not a enum-list, fall to std
QComboBox* editor = new QComboBox( parent);
editor->setSizeAdjustPolicy(QComboBox::AdjustToContents);
editor->addItems( varList.toStringList());
editor->setMaximumWidth( editor->minimumSizeHint().width());
//// Get value snapshot into editor
editor->setCurrentIndex( editor->findText( value.toString()));
return editor;
}
default:;
}
if (index.column() == 0) {
emit itemEditTrigged( index);
return 0; // No inline editor
}
QWidget* editor = QItemDelegate::createEditor( parent, option, index);
//// Get value snapshot into editor
QItemDelegate::setEditorData( editor, index);
return editor;
//.........这里部分代码省略.........
示例3: KDialog
static mpdm_t kde4_drv_form(mpdm_t a, mpdm_t ctxt)
{
int n;
mpdm_t widget_list;
QWidget *qlist[100];
mpdm_t r;
KDialog *dialog = new KDialog(window);
dialog->setModal(true);
dialog->setButtons(KDialog::Ok | KDialog::Cancel);
widget_list = mpdm_aget(a, 0);
KVBox *vb = new KVBox(dialog);
dialog->setMainWidget(vb);
for (n = 0; n < mpdm_size(widget_list); n++) {
mpdm_t w = mpdm_aget(widget_list, n);
wchar_t *type;
mpdm_t t;
KHBox *hb = new KHBox(vb);
type = mpdm_string(mpdm_hget_s(w, L"type"));
if ((t = mpdm_hget_s(w, L"label")) != NULL) {
QLabel *ql = new QLabel(hb);
ql->setText(str_to_qstring(mpdm_gettext(t)));
}
t = mpdm_hget_s(w, L"value");
if (wcscmp(type, L"text") == 0) {
mpdm_t h;
QComboBox *ql = new QComboBox(hb);
ql->setEditable(true);
ql->setMinimumContentsLength(30);
ql->setMaxVisibleItems(8);
if (t != NULL)
ql->setEditText(str_to_qstring(t));
qlist[n] = ql;
if ((h = mpdm_hget_s(w, L"history")) != NULL) {
int i;
/* has history; fill it */
h = mp_get_history(h);
for (i = mpdm_size(h) - 1; i >= 0; i--)
ql->addItem(str_to_qstring(mpdm_aget(h, i)));
}
}
else
if (wcscmp(type, L"password") == 0) {
QLineEdit *ql = new QLineEdit(hb);
ql->setEchoMode(QLineEdit::Password);
qlist[n] = ql;
}
else
if (wcscmp(type, L"checkbox") == 0) {
QCheckBox *qc = new QCheckBox(hb);
if (mpdm_ival(t))
qc->setCheckState(Qt::Checked);
qlist[n] = qc;
}
else
if (wcscmp(type, L"list") == 0) {
int i;
QListWidget *ql = new QListWidget(hb);
ql->setMinimumWidth(480);
/* use a monospaced font */
ql->setFont(QFont(QString("Mono")));
mpdm_t l = mpdm_hget_s(w, L"list");
for (i = 0; i < mpdm_size(l); i++)
ql->addItem(str_to_qstring(mpdm_aget(l, i)));
ql->setCurrentRow(mpdm_ival(t));
qlist[n] = ql;
}
if (n == 0)
qlist[n]->setFocus(Qt::OtherFocusReason);
}
n = dialog->exec();
if (!n)
return NULL;
//.........这里部分代码省略.........