static PyObject *meth_QAbstractItemDelegate_sizeHint(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; PyObject *sipOrigSelf = sipSelf; { const QStyleOptionViewItem * a0; const QModelIndex * a1; QAbstractItemDelegate *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ9J9", &sipSelf, sipType_QAbstractItemDelegate, &sipCpp, sipType_QStyleOptionViewItem, &a0, sipType_QModelIndex, &a1)) { QSize *sipRes; if (!sipOrigSelf) { sipAbstractMethod(sipName_QAbstractItemDelegate, sipName_sizeHint); return NULL; } Py_BEGIN_ALLOW_THREADS sipRes = new QSize(sipCpp->sizeHint(*a0,*a1)); Py_END_ALLOW_THREADS return sipConvertFromNewType(sipRes,sipType_QSize,NULL); } }
void TreeView::startDrag(Qt::DropActions supportedActions) { QModelIndex index = selectedIndexes().value(0); if (!index.isValid()) return; QMimeData *data = model()->mimeData(QModelIndexList() << index); if (!data) return; QRect rect; QPixmap pixmap; QPoint point; { QAbstractItemDelegate *delegate = itemDelegate(index); QStyleOptionViewItemV4 option = viewOptions(); option.locale = this->locale(); option.locale.setNumberOptions(QLocale::OmitGroupSeparator); option.widget = this; option.state |= QStyle::State_Selected; option.rect = visualRect(index); point = option.rect.topLeft(); option.rect.moveTo(0, 0); option.rect.setSize(delegate->sizeHint(option, index)); rect = option.rect; pixmap = QPixmap(rect.size()); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); delegate->paint(&painter, option, index); } QDrag *drag = new QDrag(this); drag->setPixmap(pixmap); drag->setMimeData(data); point = QCursor::pos() - viewport()->mapToGlobal(point); drag->setHotSpot(point); // drag->setHotSpot(QCursor::pos() - rect.topLeft()); Qt::DropAction setDefaultDropAction = QAbstractItemView::defaultDropAction(); Qt::DropAction defaultDropAction = Qt::IgnoreAction; if (setDefaultDropAction != Qt::IgnoreAction && (supportedActions & setDefaultDropAction)) defaultDropAction = setDefaultDropAction; else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove) defaultDropAction = Qt::CopyAction; if (drag->exec(supportedActions, defaultDropAction) == Qt::IgnoreAction && index.data(ItemTypeRole).toInt() == ContactType) { if (QWidget *widget = QApplication::topLevelAt(QCursor::pos())) { if (widget->window() == this->window()) return; } Event ev("contact-list-drop", QCursor::pos() - point, index.data(BuddyRole)); ev.send(); } // debug() << "DropAction" << drag->exec(supportedActions, defaultDropAction); // if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction) // d->clearOrRemove(); // {} }
int toResultTableView::visibleRows() const { // TODO this is ugly hack and needs some validation //this->visibleRegion(); int h = sizeHintForRow(0); QAbstractItemDelegate *d = itemDelegate(); QSize s = d->sizeHint(QStyleOptionViewItem(), QModelIndex()); int hh = height(); int hhh = s.height(); int rows = hh / s.height() + 1; if (rows < toConfigurationNewSingle::Instance().option(ToConfiguration::Database::InitialFetchInt).toInt()) return toConfigurationNewSingle::Instance().option(ToConfiguration::Database::InitialFetchInt).toInt(); return rows; }
QSize PopupListWidget::sizeHint() const { QAbstractItemModel *model = this->model(); QAbstractItemDelegate *delegate = this->itemDelegate(); const QStyleOptionViewItem sovi; int left, top, right, bottom = 0; #if QT_VERSION >= 0x040600 QMargins margin = this->contentsMargins(); top = margin.top(); bottom = margin.bottom(); left = margin.left(); right = margin.right(); #else getContentsMargins(&left, &top, &right, &bottom); #endif const int vOffset = top + bottom; const int hOffset = left + right; bool vScrollOn = false; int height = 0; int width = 0; for (int i = 0; i < this->count(); ++i) { QModelIndex index = model->index(i, 0); QSize itemSizeHint = delegate->sizeHint(sovi, index); if (itemSizeHint.width() > width) width = itemSizeHint.width(); // height const int nextHeight = height + itemSizeHint.height(); if (nextHeight + vOffset < this->maximumHeight()) height = nextHeight; else { // early termination vScrollOn = true; break; } } QSize sizeHint(width + hOffset, 0); sizeHint.setHeight(height + vOffset); if (vScrollOn) { int scrollWidth = this->verticalScrollBar()->sizeHint().width(); sizeHint.setWidth(sizeHint.width() + scrollWidth); } return sizeHint; }
int QCustomTableWidget::sizeHintForColumn(int column) const { QStyleOptionViewItem option(viewOptions()); int hint = 0; QAbstractItemDelegate *delegate = itemDelegate(); QAbstractItemModel *itemModel = model(); for(int row = 0; row < rowCount(); row++) { hint = qMax(hint, delegate->sizeHint(option, itemModel->index(row,column)).width()); } if (showGrid()) { hint++; } return hint; }