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); } }
static PyObject *meth_QAbstractItemDelegate_paint(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; PyObject *sipOrigSelf = sipSelf; { QPainter * a0; const QStyleOptionViewItem * a1; const QModelIndex * a2; QAbstractItemDelegate *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ8J9J9", &sipSelf, sipType_QAbstractItemDelegate, &sipCpp, sipType_QPainter, &a0, sipType_QStyleOptionViewItem, &a1, sipType_QModelIndex, &a2)) { if (!sipOrigSelf) { sipAbstractMethod(sipName_QAbstractItemDelegate, sipName_paint); return NULL; } Py_BEGIN_ALLOW_THREADS sipCpp->paint(a0,*a1,*a2); Py_END_ALLOW_THREADS Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QAbstractItemDelegate, sipName_paint, NULL); return NULL; }
bool EditorWidget::verifyContents() { //If any cells are currently edited add their contents //to the tableWidget QWidget *cellWidget = m_tableWidget->cellWidget(m_tableWidget->currentRow(), m_tableWidget->currentColumn()); if (cellWidget) { QAbstractItemDelegate *delegate = m_tableWidget->itemDelegateForColumn(m_tableWidget->currentColumn()); if (delegate) { delegate->setModelData(cellWidget,m_tableWidget->model(),m_tableWidget->currentIndex()); } } QString repoUID = m_repoUID->text(); if (!checkID(repoUID)) { QMessageBox::warning(this, tr("Invalid input"), tr("The '%1' field is invalid, " "it must be a hexidecimal number no longer than 8 digits.") .arg(m_repoLabel->text())); m_repoUID->setFocus(); return false; } QString keyId; QString path; #ifdef INCL_TYPE QString type; #endif for(int i=0; i < m_tableWidget->rowCount(); i++) { keyId = m_tableWidget->item(i, EditorWidget::KeyId)->text(); if (!checkID(keyId)) { QMessageBox::warning(this, tr("Invalid Key ID"), tr("The Key ID field is invalid, it must be a hexidecimal number no longer than 8 digits")); m_tableWidget->setCurrentCell(i, EditorWidget::KeyId); m_tableWidget->setFocus(); return false; } path = m_tableWidget->item(i, EditorWidget::Path)->text(); if (path.isEmpty() || !path.startsWith(QLatin1Char('/'))) { QMessageBox::warning(this, tr("Invalid Path"), tr("The Key Path field is invalid, it must not be empty and start with a /")); m_tableWidget->setCurrentCell(i, EditorWidget::Path); m_tableWidget->setFocus(); return false; } #ifdef INCL_TYPE type = m_tableWidget->item(i, EditorWidget::Type)->text(); if (type.isEmpty()) { QMessageBox::warning(this, tr("Invalid Type"), tr("The Type field is invalid, it must not be empty")); m_tableWidget->setCurrentCell(i, EditorWidget::Type); m_tableWidget->setFocus(); return false; } #endif } return true; }
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(); // {} }
QWidget* SettingsBottomView::createEditorForIndex(const QModelIndex& index) { QAbstractItemDelegate* delegate = itemDelegate(index); QStyleOptionViewItem sovi; sovi.displayAlignment = Qt::AlignRight; sovi.decorationPosition = QStyleOptionViewItem::Right; QWidget* editor = delegate->createEditor(NULL, sovi, index); delegate->setEditorData(editor, index); return editor; }
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; }
void SettingsBottomView::dataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight) { QModelIndex parent = topLeft.parent(); // If modifying data for a group, don't do anything if (!parent.isValid()) return; // Don't allow modifying more than one data element if (topLeft != bottomRight) { qDebug() << "Warning: the settings view does not allow batch modification"; return; } QScrollArea* scrollArea = qobject_cast<QScrollArea*>(stack->widget(parent.row())); QWidget* page = scrollArea->widget(); QGridLayout* layout = qobject_cast<QGridLayout*>(page->layout()); QWidget* widget; QLayoutItem* item; // Setting description item = layout->itemAtPosition(topLeft.row(), 0); QString description = getSettingDescription(topLeft); if (!item) { widget = new QLabel(description, NULL); layout->addWidget(widget, topLeft.row(), 0); } else { widget = item->widget(); qobject_cast<QLabel*>(widget)->setText(description); } // Setting value item = layout->itemAtPosition(topLeft.row(), 1); if (!item) { widget = createEditorForIndex(topLeft); layout->addWidget(widget, topLeft.row(), 1); widget->show(); } else { widget = item->widget(); } QAbstractItemDelegate* delegate = itemDelegate(topLeft); delegate->setEditorData(widget, topLeft); }