本文整理汇总了C++中ItemWidget::widget方法的典型用法代码示例。如果您正苦于以下问题:C++ ItemWidget::widget方法的具体用法?C++ ItemWidget::widget怎么用?C++ ItemWidget::widget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemWidget
的用法示例。
在下文中一共展示了ItemWidget::widget方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paint
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
int row = index.row();
ItemWidget *w = m_cache[row];
if (w == NULL)
return;
const QRect &rect = option.rect;
/* render background (selected, alternate, ...) */
QStyle *style = m_parent->style();
style->drawControl(QStyle::CE_ItemViewItem, &option, painter);
QPalette::ColorRole role = option.state & QStyle::State_Selected ?
QPalette::HighlightedText : QPalette::Text;
/* render number */
QRect numRect(0, 0, 0, 0);
if (m_showNumber) {
QString num = QString::number(row) + " ";
painter->save();
painter->setFont(m_numberFont);
style->drawItemText(painter, rect.translated(4, 4), 0,
m_numberPalette, true, num,
role);
painter->restore();
numRect = style->itemTextRect( QFontMetrics(m_numberFont), rect, 0,
true, num );
}
/* highlight search string */
w->setHighlight(m_re, m_foundFont, m_foundPalette);
/* text color for selected/unselected item */
QPalette palette = w->widget()->palette();
palette.setColor( QPalette::Text, option.palette.color(role) );
w->widget()->setPalette(palette);
/* render widget */
w->widget()->show();
}
示例2: onItemChanged
void ItemDelegate::onItemChanged(ItemWidget *item)
{
for( int i = 0; i < m_cache.length(); ++i ) {
ItemWidget *w = m_cache[i];
if ( w != NULL && w == item ) {
QSize oldSize = w->widget()->size();
emit rowChanged(i, oldSize);
return;
}
}
}
示例3: setItemMaximumSize
void ItemDelegate::setItemMaximumSize(const QSize &size)
{
int w = size.width() - 8;
if (m_showNumber) {
w -= QFontMetrics(m_numberFont).boundingRect( QString("0123") ).width();
}
if (m_maxSize.width() == w)
return;
m_maxSize.setWidth(w);
for( int i = 0; i < m_cache.length(); ++i ) {
ItemWidget *w = m_cache[i];
if (w != NULL) {
QSize oldSize = w->widget()->size();
w->widget()->setMaximumSize(m_maxSize);
w->updateSize();
emit rowChanged(i, oldSize);
}
}
}
示例4: updateRowPosition
void ItemDelegate::updateRowPosition(int row, const QPoint &position)
{
ItemWidget *w = m_cache[row];
if (w == NULL)
return;
int x = position.x();
int y = position.y();
if (m_showNumber)
x += QFontMetrics(m_numberFont).boundingRect( QString("0123") ).width();
w->widget()->move(x, y);
y += w->widget()->height();
for (int i = row + 1; i < m_cache.size(); ++i ) {
w = m_cache[i];
if (w == NULL)
continue;
if (w->widget()->y() < y)
w->widget()->hide();
}
}
示例5: paint
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
int row = index.row();
ItemWidget *w = m_cache[row];
if (w == NULL)
return;
const QRect &rect = option.rect;
bool isSelected = option.state & QStyle::State_Selected;
/* render background (selected, alternate, ...) */
QStyle *style = m_view->style();
style->drawControl(QStyle::CE_ItemViewItem, &option, painter, m_view);
/* render number */
if (m_showRowNumber) {
const QString num = QString::number(row);
QPalette::ColorRole role = isSelected ? QPalette::HighlightedText : QPalette::Text;
painter->save();
painter->setFont(m_rowNumberFont);
style->drawItemText(painter, rect.translated(m_hMargin / 2, m_vMargin), 0,
m_rowNumberPalette, true, num,
role);
painter->restore();
}
/* highlight search string */
w->setHighlight(m_re, m_foundFont, m_foundPalette);
/* text color for selected/unselected item */
QWidget *ww = w->widget();
if ( ww->property(propertySelectedItem) != isSelected ) {
ww->setProperty(propertySelectedItem, isSelected);
if ( !ww->property("CopyQ_no_style").toBool() ) {
ww->setStyle(style);
foreach (QWidget *child, ww->findChildren<QWidget *>())
child->setStyle(style);
ww->update();
}
}
}
示例6: eventFilter
bool ItemDelegate::eventFilter(QObject *object, QEvent *event)
{
if (object->objectName() == "editor") {
QPlainTextEdit *editor = qobject_cast<QPlainTextEdit*>(object);
if (editor == NULL)
return false;
QEvent::Type type = event->type();
if ( type == QEvent::KeyPress ) {
QKeyEvent *keyevent = static_cast<QKeyEvent *>(event);
switch ( keyevent->key() ) {
case Qt::Key_Enter:
case Qt::Key_Return:
// Commit data on Ctrl+Return or Enter?
if (m_saveOnReturnKey) {
if (keyevent->modifiers() == Qt::ControlModifier) {
editor->insertPlainText("\n");
return true;
} else if (keyevent->modifiers() != Qt::NoModifier) {
return false;
}
} else {
if (keyevent->modifiers() != Qt::ControlModifier)
return false;
}
emit commitData(editor);
emit closeEditor(editor);
return true;
case Qt::Key_S:
// Commit data on Ctrl+S.
if (keyevent->modifiers() != Qt::ControlModifier)
return false;
emit commitData(editor);
emit closeEditor(editor);
return true;
case Qt::Key_F2:
// Commit data on F2.
emit commitData(editor);
emit closeEditor(editor);
return true;
case Qt::Key_Escape:
// Close editor without committing data.
emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache);
return true;
default:
return false;
}
} else if ( type == QEvent::ContextMenu ) {
QAction *act;
QMenu *menu = editor->createStandardContextMenu();
connect( menu, SIGNAL(aboutToHide()), menu, SLOT(deleteLater()) );
menu->setParent(editor);
act = menu->addAction( tr("&Save Item") );
act->setShortcut( QKeySequence(tr("F2, Ctrl+Enter")) );
connect( act, SIGNAL(triggered()), this, SLOT(editorSave()) );
act = menu->addAction( tr("Cancel Editing") );
act->setShortcut( QKeySequence(tr("Escape")) );
connect( act, SIGNAL(triggered()), this, SLOT(editorCancel()) );
QContextMenuEvent *menuEvent = static_cast<QContextMenuEvent *>(event);
menu->popup( menuEvent->globalPos() );
}
} else {
// resize event for items
if (event->type() == QEvent::Resize) {
QResizeEvent *resize = static_cast<QResizeEvent *>(event);
ItemWidget *item = dynamic_cast<ItemWidget *>(object);
if (item != NULL) {
item->widget()->resize(resize->size());
onItemChanged(item);
return true;
}
}
}
return false;
}
示例7: hideRow
void ItemDelegate::hideRow(int row)
{
ItemWidget *w = m_cache[row];
if (w != NULL)
w->widget()->hide();
}
示例8: setRowVisible
void ItemDelegate::setRowVisible(int row, bool visible)
{
ItemWidget *w = m_cache[row];
if (w != NULL)
w->widget()->setVisible(visible);
}
示例9: updateRowPosition
void ItemDelegate::updateRowPosition(int row, int y)
{
ItemWidget *w = m_cache[row];
if (w != NULL)
w->widget()->move( QPoint(rowNumberWidth() + m_hMargin, y + m_vMargin) );
}