本文整理汇总了C++中QStyle::drawControl方法的典型用法代码示例。如果您正苦于以下问题:C++ QStyle::drawControl方法的具体用法?C++ QStyle::drawControl怎么用?C++ QStyle::drawControl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStyle
的用法示例。
在下文中一共展示了QStyle::drawControl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintButton
bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
QStyle* style = 0;
QPainter* painter = 0;
QWidget* widget = 0;
if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget))
return true;
QStyleOptionButton option;
option.initFrom(widget);
option.rect = r;
// Get the correct theme data for a button
EAppearance appearance = applyTheme(option, o);
if(appearance == PushButtonAppearance || appearance == ButtonAppearance)
style->drawControl(QStyle::CE_PushButton, &option, painter);
else if(appearance == RadioAppearance)
style->drawControl(QStyle::CE_RadioButton, &option, painter);
else if(appearance == CheckboxAppearance)
style->drawControl(QStyle::CE_CheckBox, &option, painter);
return false;
}
示例2: paintWeekScaleHeader
/*! Paints the week scale header.
* \sa paintHeader()
*/
void DateTimeGrid::paintWeekScaleHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect,
qreal offset, QWidget* widget )
{
QStyle* style = widget?widget->style():QApplication::style();
// Paint a section for each week
QDateTime sdt = d->chartXtoDateTime( offset+exposedRect.left() );
sdt.setTime( QTime( 0, 0, 0, 0 ) );
// Go backwards until start of week
while ( sdt.date().dayOfWeek() != d->weekStart ) sdt = sdt.addDays( -1 );
QDateTime dt = sdt;
for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right()+offset;
dt = dt.addDays( 7 ),x=d->dateTimeToChartX( dt ) ) {
QStyleOptionHeader opt;
opt.init( widget );
opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth()*7, headerRect.height()/2. ).toRect();
opt.text = QString::number( dt.date().weekNumber() );
opt.textAlignment = Qt::AlignCenter;
// NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here
style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget );
QStyleOptionHeader subopt = opt;
subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget );
if ( subopt.rect.isValid() ) {
style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget );
}
}
// Paint a section for each month
dt = sdt;
for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset; x2=d->dateTimeToChartX( dt ) ) {
//qDebug()<<"paintWeekScaleHeader()"<<dt;
QDate next = dt.date().addMonths( 1 );
next = next.addDays( 1 - next.day() );
QStyleOptionHeader opt;
opt.init( widget );
opt.rect = QRectF( x2-offset, headerRect.top(), dayWidth()*dt.date().daysTo( next ), headerRect.height()/2. ).toRect();
opt.text = QDate::longMonthName( dt.date().month() );
opt.textAlignment = Qt::AlignCenter;
// NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here
style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget );
QStyleOptionHeader subopt = opt;
subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget );
if ( subopt.rect.isValid() ) {
style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget );
}
dt.setDate( next );
}
}
示例3: paint
void LevelDelegate::paint (QPainter * painter, QStyleOptionViewItem const & option, QModelIndex const & index) const
{
//if (m_app_data && m_app_data->getDictCtx().m_names.size())
painter->save();
QStyleOptionViewItemV4 option4 = option;
initStyleOption(&option4, index);
if (index.column() == 0)
{
QVariant value = index.data(Qt::DisplayRole);
if (value.isValid() && !value.isNull())
{
QString const qs = value.toString();
int const lvl = qs.toInt();
// @TODO: this should be exchanged via dictionnary in future
if (lvl >= 0 && lvl < trace::e_max_trace_level)
{
option4.text = QString::fromLatin1(trace::enumToString(static_cast<trace::E_TraceLevel>(lvl)));
}
if (QWidget const * widget = option4.widget)
{
QStyle * style = widget->style();
style->drawControl(QStyle::CE_ItemViewItem, &option4, painter, widget);
}
}
}
else if (index.column() == 1)
{
QVariant value = index.data(Qt::DisplayRole);
if (value.isValid() && !value.isNull())
{
QString const qs = value.toString();
E_LevelMode const mode = stringToLvlMod(qs.at(0).toLatin1());
QString const verbose = lvlmodsStr[mode];
option4.text = verbose;
if (QWidget const * widget = option4.widget)
{
QStyle * style = widget->style();
style->drawControl(QStyle::CE_ItemViewItem, &option4, painter, widget);
}
}
}
else
QStyledItemDelegate::paint(painter, option4, index);
painter->restore();
}
示例4: initStyleOption
void
SqlSearchDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyleOptionViewItemV4 optionV4 = option;
initStyleOption(&optionV4, index);
QStyle *style = optionV4.widget? optionV4.widget->style() : QApplication::style();
QTextDocument doc;
doc.setHtml(optionV4.text);
optionV4.text = QString();
style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
QAbstractTextDocumentLayout::PaintContext ctx;
QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
(option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive : QPalette::Disabled;
if (optionV4.state & QStyle::State_Selected)
ctx.palette.setColor(QPalette::Text, optionV4.palette.color(cg, QPalette::HighlightedText));
else
ctx.palette.setColor(QPalette::Text, optionV4.palette.color(cg, QPalette::WindowText));
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4);
painter->save();
painter->translate(textRect.topLeft());
painter->setClipRect(textRect.translated(-textRect.topLeft()));
doc.documentLayout()->draw(painter, ctx);
painter->restore();
}
示例5: paintTokenized
void LogDelegate::paintTokenized (QPainter * painter, QStyleOptionViewItemV4 & option4, QModelIndex const & index, QString const & separator, QString const & out_separator, int level) const
{
QVariant value = index.data(Qt::DisplayRole);
if (value.isValid() && !value.isNull())
{
QStringList list = value.toString().split(QRegExp(separator), QString::SkipEmptyParts);
if (level < list.size())
{
QString p;
for (int i = list.size() - level, ie = list.size(); i < ie; ++i)
{
if (i > 0)
p.append(out_separator);
p.append(list.at(i));
}
option4.text = p;
}
QWidget const * widget = option4.widget;
if (widget)
{
QStyle * style = widget->style();
style->drawControl(QStyle::CE_ItemViewItem, &option4, painter, widget);
}
}
}
示例6: paint
void HtmlDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,const QModelIndex &index) const
{
QStyleOptionViewItemV4 optionV4(option);
initStyleOption(&optionV4, index);
QStyle *style = optionV4.widget ? optionV4.widget->style() : QApplication::style();
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &optionV4, painter, optionV4.widget);
QTextDocument doc;
QString text = optionV4.text;
doc.setHtml(text);
doc.setPageSize( option.rect.size() );
/// Painting item without text
optionV4.text.clear();
style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
QAbstractTextDocumentLayout::PaintContext ctx;
// Highlighting text if item is selected
if (optionV4.state & QStyle::State_Selected)
ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));
QRect textRect = option.rect;
painter->save();
painter->translate(textRect.topLeft());
painter->setClipRect(textRect.translated(-textRect.topLeft()));
doc.documentLayout()->draw(painter, ctx);
painter->restore();
}
示例7: renderHelper
// static
void StarEditor::renderHelper(QPainter* painter,
QTableView* pTableView,
const QStyleOptionViewItemV4& option,
StarRating* pStarRating) {
painter->save();
painter->setClipRect(option.rect);
if (pTableView != NULL) {
QStyle* style = pTableView->style();
if (style != NULL) {
style->drawControl(QStyle::CE_ItemViewItem, &option, painter,
pTableView);
}
}
// Set the palette appropriately based on whether the row is selected or
// not. We also have to check if it is inactive or not and use the
// appropriate ColorGroup.
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
? QPalette::Normal : QPalette::Disabled;
if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
cg = QPalette::Inactive;
if (option.state & QStyle::State_Selected) {
painter->setBrush(option.palette.color(cg, QPalette::HighlightedText));
} else {
painter->setBrush(option.palette.color(cg, QPalette::Text));
}
pStarRating->paint(painter, option.rect);
painter->restore();
}
示例8: paint
//////// delegate
void ScriptDelegate::paint (QPainter * painter, QStyleOptionViewItem const & option, QModelIndex const & index) const
{
painter->save();
QStyleOptionViewItemV4 option4 = option;
initStyleOption(&option4, index);
if (index.column() == 1)
{
QVariant value = index.data(Qt::DisplayRole);
if (value.isValid() && !value.isNull())
{
QString const qs = value.toString();
E_FilterMode const mode = stringToFltMod(qs.at(0).toLatin1());
QString const verbose = fltmodsStr[mode];
option4.text = verbose;
if (QWidget const * widget = option4.widget)
{
QStyle * style = widget->style();
style->drawControl(QStyle::CE_ItemViewItem, &option4, painter, widget);
}
}
}
else
QStyledItemDelegate::paint(painter, option4, index);
painter->restore();
}
示例9: paint
void ChatDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionViewItemV4 optionV4(option);
this->initStyleOption(&optionV4, index);
optionV4.state = option.state & (~QStyle::State_HasFocus);
QStyle* style = optionV4.widget ? optionV4.widget->style() : QApplication::style();
this->textDocument.setHtml(optionV4.text);
this->textDocument.setTextWidth(optionV4.rect.width());
optionV4.text = QString();
style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter, optionV4.widget);
QAbstractTextDocumentLayout::PaintContext ctx;
ctx.palette = optionV4.palette;
// Highlighting text if item is selected.
if (optionV4.state & QStyle::State_Selected && optionV4.state & QStyle::State_Active)
ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4);
painter->save();
painter->translate(textRect.topLeft());
painter->setClipRect(textRect.translated(-textRect.topLeft()));
this->textDocument.documentLayout()->draw(painter, ctx);
painter->restore();
}
示例10: drawProgressBar
void KoDocumentSectionDelegate::drawProgressBar(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QVariant value = index.data(KoDocumentSectionModel::ProgressRole);
if (!value.isNull() && (value.toInt() >= 0 && value.toInt() <= 100)) {
const QRect r = progressBarRect(option, index).translated(option.rect.topLeft());
p->save();
{
p->setClipRect(r);
QStyle* style = QApplication::style();
QStyleOptionProgressBarV2 opt;
opt.minimum = 0;
opt.maximum = 100;
opt.progress = value.toInt();
opt.textVisible = true;
opt.textAlignment = Qt::AlignHCenter;
opt.text = QObject::tr("%1 %").arg(opt.progress);
opt.rect = r;
opt.orientation = Qt::Horizontal;
opt.state = option.state;
style->drawControl(QStyle::CE_ProgressBar, &opt, p, 0);
}
p->restore();
}
}
示例11: paint
void LogbookDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QStyle * style;
QStyleOptionViewItemV4 opt(option);
initStyleOption(& opt, index);
// Remove the Focus Rectangle
opt.state &= ~(QStyle::State_HasFocus);
// Make the Text Uppercase for Root Items
if (! index.parent().isValid())
{
opt.font.setBold(true);
opt.font.setCapitalization(QFont::AllUppercase);
opt.palette.setColor(QPalette::Text, Qt::darkGray);
}
// Draw the Item
if (opt.widget == NULL)
style = QApplication::style();
else
style = opt.widget->style();
style->drawControl(QStyle::CE_ItemViewItem, & opt, painter, opt.widget);
}
示例12: paint
void MessageViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItemV4 optionV4 = option;
initStyleOption(&optionV4, index);
QStyle *style = optionV4.widget? optionV4.widget->style() : QApplication::style();
QTextDocument doc;
QString align(index.data(MessageModel::TypeRole) == 1 ? "left" : "right");
QString html = "<p align=\"" + align + "\" style=\"color:black;\">" + index.data(MessageModel::HTMLRole).toString() + "</p>";
doc.setHtml(html);
/// Painting item without text
optionV4.text = QString();
style->drawControl(QStyle::CE_ItemViewItem, &optionV4, painter);
QAbstractTextDocumentLayout::PaintContext ctx;
// Highlighting text if item is selected
if (optionV4.state & QStyle::State_Selected)
ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText));
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4);
doc.setTextWidth( textRect.width() );
painter->save();
painter->translate(textRect.topLeft());
painter->setClipRect(textRect.translated(-textRect.topLeft()));
doc.documentLayout()->draw(painter, ctx);
painter->restore();
}
示例13: paintDayScaleHeader
/*! Paints the day scale header.
* \sa paintHeader()
*/
void DateTimeGrid::paintDayScaleHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect,
qreal offset, QWidget* widget )
{
// For starters, support only the regular tab-per-day look
QStyle* style = widget?widget->style():QApplication::style();
// Paint a section for each day
QDateTime dt = d->chartXtoDateTime( offset+exposedRect.left() );
dt.setTime( QTime( 0, 0, 0, 0 ) );
for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right()+offset;
dt = dt.addDays( 1 ),x=d->dateTimeToChartX( dt ) ) {
QStyleOptionHeader opt;
opt.init( widget );
opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth(), headerRect.height()/2. ).toRect();
opt.text = dt.toString( QString::fromAscii( "ddd" ) ).left( 1 );
opt.textAlignment = Qt::AlignCenter;
// NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here
style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget );
QStyleOptionHeader subopt = opt;
subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget );
if ( subopt.rect.isValid() ) {
style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget );
}
}
dt = d->chartXtoDateTime( offset+exposedRect.left() );
dt.setTime( QTime( 0, 0, 0, 0 ) );
// Go backwards until start of week
while ( dt.date().dayOfWeek() != d->weekStart ) dt = dt.addDays( -1 );
// Paint a section for each week
for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset;
dt = dt.addDays( 7 ),x2=d->dateTimeToChartX( dt ) ) {
QStyleOptionHeader opt;
opt.init( widget );
opt.rect = QRectF( x2-offset, headerRect.top(), dayWidth()*7., headerRect.height()/2. ).toRect();
opt.text = QString::number( dt.date().weekNumber() );
opt.textAlignment = Qt::AlignCenter;
// NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here
style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget );
QStyleOptionHeader subopt = opt;
subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget );
if ( subopt.rect.isValid() ) {
style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget );
}
}
}
示例14: drawDisplay
void ShortcutDelegate::drawDisplay(QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect, const QString & text) const {
QStyle *style = QApplication::style();
if (!style) QItemDelegate::drawDisplay(painter, option, rect, text);
else if (text=="<internal: delete row>") {
QStyleOptionButton sob;
sob.text = tr("delete row");
sob.state = QStyle::State_Enabled;
sob.rect = rect;
style->drawControl(QStyle::CE_PushButton, &sob, painter);
} else if (text=="<internal: add row>") {
QStyleOptionButton sob;
sob.text = tr("add row");
sob.state = QStyle::State_Enabled;
sob.rect = rect;
style->drawControl(QStyle::CE_PushButton, & sob, painter);
} else QItemDelegate::drawDisplay(painter, option, rect, text);
}
示例15: drawBackground
void ExpandingDelegate::drawBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(index)
QStyleOptionViewItemV4 opt = option;
//initStyleOption(&opt, index);
//Problem: This isn't called at all, because drawBrackground is not virtual :-/
QStyle *style = model()->treeView()->style() ? model()->treeView()->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
}