本文整理汇总了C++中QStyle::proxy方法的典型用法代码示例。如果您正苦于以下问题:C++ QStyle::proxy方法的具体用法?C++ QStyle::proxy怎么用?C++ QStyle::proxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStyle
的用法示例。
在下文中一共展示了QStyle::proxy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawFocusRect
void IconsetDelegate::drawFocusRect(QPainter *APainter, const QStyleOptionViewItemV4 &AIndexOption, const QRect &ARect) const
{
if ((AIndexOption.state & QStyle::State_HasFocus) > 0)
{
QStyle *style = AIndexOption.widget ? AIndexOption.widget->style() : QApplication::style();
QStyleOptionFocusRect focusOption;
focusOption.QStyleOption::operator=(AIndexOption);
focusOption.rect = ARect;
focusOption.state |= QStyle::State_KeyboardFocusChange|QStyle::State_Item;
QPalette::ColorGroup cg = (AIndexOption.state & QStyle::State_Enabled) ? QPalette::Normal : QPalette::Disabled;
QPalette::ColorRole cr = (AIndexOption.state & QStyle::State_Selected) ? QPalette::Highlight : QPalette::Window;
focusOption.backgroundColor = AIndexOption.palette.color(cg,cr);
style->proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOption, APainter);
}
}
示例2: paint
void ProcessItemDelegate::paint(QPainter * painter,
const QStyleOptionViewItem &option, const QModelIndex & index) const
{
QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt, index);
painter->save();
painter->setClipRect(opt.rect);
// Draw the background.
const QWidget * widget = opt.widget;
QStyle * style = widget ? widget->style() : QApplication::style();
style->proxy()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, widget);
QRect iconRect = style->subElementRect(QStyle::SE_ItemViewItemDecoration, &opt,
widget);
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, widget);
// Draw the icon.
QIcon::Mode mode = QIcon::Normal;
if (!(opt.state & QStyle::State_Enabled))
{
mode = QIcon::Disabled;
}
else if (opt.state & QStyle::State_Selected)
{
mode = QIcon::Selected;
}
QIcon::State state = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off;
opt.icon.paint(painter, iconRect, opt.decorationAlignment, mode, state);
// Draw the text.
QTextDocument doc;
doc.setHtml(opt.text);
doc.setDocumentMargin(2);
painter->translate(textRect.topLeft());
doc.drawContents(painter);
painter->restore();
}
示例3: paint
// Based on QCommonStyle::drawControl case CE_ItemViewItem
void FilesDelegate::paint( QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
// QStyledItemDelegate::paint(p, option, index);
// return;
Q_ASSERT(index.isValid());
QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt, index);
const QWidget *widget = opt.widget;
const QTreeView *view = qobject_cast<const QTreeView *>(widget);
QStyle *style = widget ? widget->style() : qApp->style();
// style->drawControl(QStyle::CE_ItemViewItem, &opt, p, widget);
// return;
#if defined(Q_OS_WIN32)
// Based on QWindowsVistaStyle::drawControl case CE_ItemViewItem
if (FilesDelegate_win_useVista(style))
{
QPalette palette = opt.palette;
palette.setColor(QPalette::All, QPalette::HighlightedText, palette.color(QPalette::Active, QPalette::Text));
// Note that setting a saturated color here results in ugly XOR colors in the focus rect
palette.setColor(QPalette::All, QPalette::Highlight, palette.base().color().darker(108));
opt.palette = palette;
// We hide the focusrect in singleselection as it is not required
if ((view->selectionMode() == QAbstractItemView::SingleSelection) && !(opt.state & QStyle::State_KeyboardFocusChange))
opt.state &= ~QStyle::State_HasFocus;
}
#endif
// Custom padding for first and last columns; Also fixing viewItemPosition for swapped columns
if (!view->header()->logicalIndex(index.column()))
{
opt.rect.setLeft(opt.rect.left() + VIEWPORT_MARGIN_LEFT);
opt.viewItemPosition = QStyleOptionViewItemV4::Beginning;
}
if (view->header()->logicalIndex(index.column()) == index.model()->columnCount() - 1)
{
opt.rect.setRight(opt.rect.right() - VIEWPORT_MARGIN_RIGHT);
opt.viewItemPosition = QStyleOptionViewItemV4::End;
}
p->save();
p->setClipRect(opt.rect);
QRect checkRect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &opt, widget);
QRect iconRect = style->subElementRect(QStyle::SE_ItemViewItemDecoration, &opt, widget);
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, widget);
// Initially selected elements have State_Selected state, but it's not what we want, so we remove it and set background color
if (opt.state & QStyle::State_Selected)
{
opt.state &= ~(QStyle::State_Selected);
opt.backgroundBrush = QBrush(QColor(255, 215, 188)); // Soft orange-pink color for selection
}
// State_Selected state is used for displaying cursor row only
if (currentRow == index.data(FileListModel::IndexRowRole).toInt())
opt.state |= QStyle::State_Selected;
// draw the background
style->proxy()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, p, widget);
// draw the check mark
if (opt.features & QStyleOptionViewItemV2::HasCheckIndicator)
{
QStyleOptionViewItemV4 option(opt);
option.rect = checkRect;
option.state = option.state & ~QStyle::State_HasFocus;
switch (opt.checkState)
{
case Qt::Unchecked:
option.state |= QStyle::State_Off;
break;
case Qt::PartiallyChecked:
option.state |= QStyle::State_NoChange;
break;
case Qt::Checked:
option.state |= QStyle::State_On;
break;
}
style->proxy()->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &option, p, widget);
}
// draw the icon
QIcon::Mode mode = QIcon::Normal;
if (!(opt.state & QStyle::State_Enabled))
mode = QIcon::Disabled;
else if (opt.state & QStyle::State_Selected)
mode = QIcon::Selected;
QIcon::State state = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off;
opt.icon.paint(p, iconRect, opt.decorationAlignment, mode, state);
// draw the text
if (!opt.text.isEmpty())
{
//.........这里部分代码省略.........
示例4: drawBackground
void IconsetDelegate::drawBackground(QPainter *APainter, const QStyleOptionViewItemV4 &AIndexOption) const
{
QStyle *style = AIndexOption.widget ? AIndexOption.widget->style() : QApplication::style();
style->proxy()->drawPrimitive(QStyle::PE_PanelItemViewItem,&AIndexOption,APainter,AIndexOption.widget);
}
示例5: paint
void LedgerDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
// never change the background of the cell the mouse is hovering over
opt.state &= ~QStyle::State_MouseOver;
// show the focus only on the detail column
opt.state &= ~QStyle::State_HasFocus;
if(index.column() == LedgerModel::DetailColumn) {
QAbstractItemView* view = qobject_cast< QAbstractItemView* >(parent());
if(view) {
if(view->currentIndex().row() == index.row()) {
opt.state |= QStyle::State_HasFocus;
}
}
}
painter->save();
// Background
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
// Do not paint text if the edit widget is shown
const LedgerView *view = qobject_cast<const LedgerView *>(opt.widget);
if (view && view->indexWidget(index)) {
painter->restore();
return;
}
const int margin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
const QRect textArea = QRect(opt.rect.x() + margin, opt.rect.y() + margin, opt.rect.width() - 2 * margin, opt.rect.height() - 2 * margin);
QStringList lines;
if(index.column() == LedgerModel::DetailColumn) {
lines << index.model()->data(index, LedgerModel::PayeeNameRole).toString();
lines << index.model()->data(index, LedgerModel::CounterAccountRole).toString();
lines << index.model()->data(index, LedgerModel::SingleLineMemoRole).toString();
lines.removeAll(QString());
}
const bool erroneous = index.model()->data(index, LedgerModel::ErroneousRole).toBool();
const bool selected = opt.state & QStyle::State_Selected;
// draw the text items
if(!opt.text.isEmpty() || !lines.isEmpty()) {
// check if it is a scheduled transaction and display it as inactive
if(!index.model()->data(index, LedgerModel::ScheduleIdRole).toString().isEmpty()) {
opt.state &= ~QStyle::State_Enabled;
}
QPalette::ColorGroup cg = (opt.state & QStyle::State_Enabled)
? QPalette::Normal : QPalette::Disabled;
if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active)) {
cg = QPalette::Inactive;
}
if (opt.state & QStyle::State_Selected) {
painter->setPen(opt.palette.color(cg, QPalette::HighlightedText));
} else {
painter->setPen(opt.palette.color(cg, QPalette::Text));
}
if (opt.state & QStyle::State_Editing) {
painter->setPen(opt.palette.color(cg, QPalette::Text));
painter->drawRect(textArea.adjusted(0, 0, -1, -1));
}
// Don't play with the color if it's selected
// otherwise switch the color if the transaction has errors
if(erroneous && !selected) {
painter->setPen(m_erroneousColor);
}
// collect data for the various colums
if(index.column() == LedgerModel::DetailColumn) {
for(int i = 0; i < lines.count(); ++i) {
painter->drawText(textArea.adjusted(0, (opt.fontMetrics.lineSpacing() + 5) * i, 0, 0), opt.displayAlignment, lines[i]);
}
} else {
painter->drawText(textArea, opt.displayAlignment, opt.text);
}
}
// draw the focus rect
if(opt.state & QStyle::State_HasFocus) {
QStyleOptionFocusRect o;
o.QStyleOption::operator=(opt);
o.rect = style->proxy()->subElementRect(QStyle::SE_ItemViewItemFocusRect, &opt, opt.widget);
o.state |= QStyle::State_KeyboardFocusChange;
o.state |= QStyle::State_Item;
QPalette::ColorGroup cg = (opt.state & QStyle::State_Enabled)
? QPalette::Normal : QPalette::Disabled;
o.backgroundColor = opt.palette.color(cg, (opt.state & QStyle::State_Selected)
? QPalette::Highlight : QPalette::Window);
style->proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter, opt.widget);
//.........这里部分代码省略.........