本文整理汇总了C++中QStyleOptionFocusRect::initFrom方法的典型用法代码示例。如果您正苦于以下问题:C++ QStyleOptionFocusRect::initFrom方法的具体用法?C++ QStyleOptionFocusRect::initFrom怎么用?C++ QStyleOptionFocusRect::initFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStyleOptionFocusRect
的用法示例。
在下文中一共展示了QStyleOptionFocusRect::initFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void Plotter::paintEvent(QPaintEvent * /* event */)
{
QStylePainter painter(this);
painter.drawPixmap(0, 0, pixmap);
if (rubberBandIsShown)
{
painter.setPen(palette().light().color());
/*
* Using QRect::normalized() ensures that the rubber band rectangle has
* positive width and height (swap-ping coordinates if necessary),
* and adjusted() reduces the size of the rectangle by one pixel to
* allow for its own 1-pixel-wide outline.
*/
painter.drawRect(rubberBandRect.normalized()
.adjusted(0, 0, -1, -1));
}
/*
* If the Plotter has focus, a focus rectangle is drawn using the widget
* style's draw-Primitive() function with QStyle::PE_FrameFocusRect as its
* first argument and a QStyleOptionFocusRect object as its second argument.
* The focus rectangle's drawing options are inherited from the Plotter widget
* (by the initFrom() call). The background color must be specified explicitly.
*/
if (hasFocus())
{
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().dark().color();
painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
}
}
示例2: paintEvent
void DetailsButton::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
QPainter p(this);
// draw hover animation
if (!HostOsInfo::isMacHost() && !isDown() && m_fader > 0) {
// draw hover animation
if (!isDown() && m_fader > 0)
p.fillRect(rect().adjusted(1, 1, -2, -2), QColor(255, 255, 255, int(m_fader*180)));
}
if (isChecked()) {
if (m_checkedPixmap.isNull() || m_checkedPixmap.size() / m_checkedPixmap.devicePixelRatio() != contentsRect().size())
m_checkedPixmap = cacheRendering(contentsRect().size(), true);
p.drawPixmap(contentsRect(), m_checkedPixmap);
} else {
if (m_uncheckedPixmap.isNull() || m_uncheckedPixmap.size() / m_uncheckedPixmap.devicePixelRatio() != contentsRect().size())
m_uncheckedPixmap = cacheRendering(contentsRect().size(), false);
p.drawPixmap(contentsRect(), m_uncheckedPixmap);
}
if (isDown()) {
p.setPen(Qt::NoPen);
p.setBrush(QColor(0, 0, 0, 20));
p.drawRoundedRect(rect().adjusted(1, 1, -1, -1), 1, 1);
}
if (hasFocus()) {
QStyleOptionFocusRect option;
option.initFrom(this);
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &p, this);
}
}
示例3: paintEvent
void DateWidget::paintEvent(QPaintEvent *event)
{
static QPixmap pix = QPixmap(":/calendar").scaled(DATEWIDGETWIDTH, 64);
QPainter painter(this);
painter.drawPixmap(QPoint(0, 0), isEnabled() ? pix : QPixmap::fromImage(grayImage(pix.toImage())));
QString month = mDate.toString("MMM");
QString year = mDate.toString("yyyy");
QString day = mDate.toString("dd");
QFont font = QFont("monospace", 10);
QFontMetrics metrics = QFontMetrics(font);
painter.setFont(font);
painter.setPen(QPen(QBrush(Qt::white), 0));
painter.setBrush(QBrush(Qt::white));
painter.drawText(QPoint(6, metrics.height() + 1), month);
painter.drawText(QPoint(DATEWIDGETWIDTH - metrics.width(year) - 6, metrics.height() + 1), year);
font.setPointSize(14);
metrics = QFontMetrics(font);
painter.setPen(QPen(QBrush(Qt::black), 0));
painter.setBrush(Qt::black);
painter.setFont(font);
painter.drawText(QPoint(DATEWIDGETWIDTH / 2 - metrics.width(day) / 2, 45), day);
if (hasFocus()) {
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().color(QPalette::Background);
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
}
}
示例4: paintEvent
void BcExpander::paintEvent(QPaintEvent * /*event*/)
{
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing, true);
p.setPen(QPen(Qt::lightGray, 2));
if (m_count > 1) {
if (QApplication::isRightToLeft()) {
p.drawLine(5, 1, 1, 5);
p.drawLine(1, 5, 5, 9);
p.drawLine(5, 9, 9, 5);
} else {
p.drawLine(5, 1, 9, 5);
p.drawLine(9, 5, 5, 9);
p.drawLine(5, 9, 1, 5);
}
} else {
if (QApplication::isRightToLeft()) {
p.drawLine(7, 1, 3, 5);
p.drawLine(3, 5, 7, 9);
} else {
p.drawLine(3, 1, 7, 5);
p.drawLine(7, 5, 3, 9);
}
}
// focus handling
if (hasFocus()) {
QStyleOptionFocusRect opt;
opt.initFrom(this);
opt.backgroundColor = Qt::white;
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &p, this);
}
}
示例5: paintEvent
void QgsGradientStopEditor::paintEvent( QPaintEvent *event )
{
Q_UNUSED( event );
QPainter painter( this );
QRect frameRect( rect().x() + MARGIN_X, rect().y(),
rect().width() - 2 * MARGIN_X,
rect().height() - MARGIN_BOTTOM );
//draw frame
QStyleOptionFrame option;
option.initFrom( this );
option.state = hasFocus() ? QStyle::State_KeyboardFocusChange : QStyle::State_None;
option.rect = frameRect;
style()->drawPrimitive( QStyle::PE_Frame, &option, &painter );
if ( hasFocus() )
{
//draw focus rect
QStyleOptionFocusRect option;
option.initFrom( this );
option.state = QStyle::State_KeyboardFocusChange;
option.rect = frameRect;
style()->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &painter );
}
//start with the checkboard pattern
QBrush checkBrush = QBrush( transparentBackground() );
painter.setBrush( checkBrush );
painter.setPen( Qt::NoPen );
QRect box( frameRect.x() + FRAME_MARGIN, frameRect.y() + FRAME_MARGIN,
frameRect.width() - 2 * FRAME_MARGIN,
frameRect.height() - 2 * FRAME_MARGIN );
painter.drawRect( box );
// draw gradient preview on top of checkerboard
for ( int i = 0; i < box.width() + 1; ++i )
{
QPen pen( mGradient.color( static_cast< double >( i ) / box.width() ) );
painter.setPen( pen );
painter.drawLine( box.left() + i, box.top(), box.left() + i, box.height() + 1 );
}
// draw stop markers
int markerTop = frameRect.bottom() + 1;
drawStopMarker( painter, QPoint( box.left(), markerTop ), mGradient.color1(), mSelectedStop == 0 );
drawStopMarker( painter, QPoint( box.right(), markerTop ), mGradient.color2(), mSelectedStop == mGradient.count() - 1 );
int i = 1;
Q_FOREACH ( const QgsGradientStop& stop, mStops )
{
int x = stop.offset * box.width() + box.left();
drawStopMarker( painter, QPoint( x, markerTop ), stop.color, mSelectedStop == i );
++i;
}
示例6: paintEvent
void MotorLever::paintEvent(QPaintEvent *)
{
QStylePainter painter(this);
if (hasFocus()) {
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().color(QPalette::Background);
painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
}
}
示例7: paintEvent
void QIRichToolButton::paintEvent (QPaintEvent *aEvent)
{
/* Draw focus around mLabel if focused */
if (hasFocus())
{
QStylePainter painter (this);
QStyleOptionFocusRect option;
option.initFrom (this);
option.rect = mLabel->frameGeometry();
painter.drawPrimitive (QStyle::PE_FrameFocusRect, option);
}
QWidget::paintEvent (aEvent);
}
示例8: paint
void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(option);
if (m_alternateBackground) {
const QColor backgroundColor = m_styleOption.palette.color(QPalette::AlternateBase);
const QRectF backgroundRect(0, 0, size().width(), size().height());
painter->fillRect(backgroundRect, backgroundColor);
}
if (m_selected && m_editedRole.isEmpty()) {
const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0);
drawItemStyleOption(painter, widget, activeState |
QStyle::State_Enabled |
QStyle::State_Selected |
QStyle::State_Item);
}
if (m_current && m_editedRole.isEmpty()) {
QStyleOptionFocusRect focusRectOption;
focusRectOption.initFrom(widget);
focusRectOption.rect = textFocusRect().toRect();
focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange;
if (m_selected) {
focusRectOption.state |= QStyle::State_Selected;
}
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusRectOption, painter, widget);
}
if (m_hoverOpacity > 0.0) {
if (!m_hoverCache) {
// Initialize the m_hoverCache pixmap to improve the drawing performance
// when fading the hover background
m_hoverCache = new QPixmap(size().toSize());
m_hoverCache->fill(Qt::transparent);
QPainter pixmapPainter(m_hoverCache);
const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0);
drawItemStyleOption(&pixmapPainter, widget, activeState |
QStyle::State_Enabled |
QStyle::State_MouseOver |
QStyle::State_Item);
}
const qreal opacity = painter->opacity();
painter->setOpacity(m_hoverOpacity * opacity);
painter->drawPixmap(0, 0, *m_hoverCache);
painter->setOpacity(opacity);
}
}
示例9: drawItemHighlighter
QRect KexiRelationsTableFieldList::drawItemHighlighter(QPainter *painter, Q3ListViewItem *item)
{
#ifdef __GNUC__
#warning TODO KexiRelationsTableFieldList::drawItemHighlighter() OK?
#endif
if (painter) {
QStyleOptionFocusRect option;
option.initFrom(this);
option.rect = itemRect(item);
option.state |= QStyle::State_FocusAtBorder;
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, painter, this);
}
return itemRect(item);
}
示例10: paintEvent
void paintEvent( QPaintEvent* /*pPaintEvent*/ )
{
if( m_Selected )
{
QStyle* style = this->style();
QStyleOptionFocusRect option;
option.initFrom( this );
option.rect.adjust( 2, 2, -2, -2 );
QPainter painter( this );
style->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &painter, this );
}
}
示例11: paintEvent
/*!
\reimp
*/
void QxtStars::paintEvent(QPaintEvent* event)
{
QAbstractSlider::paintEvent(event);
QPainter painter(this);
painter.save();
painter.setPen(palette().color(QPalette::Text));
painter.setRenderHint(QPainter::Antialiasing);
const bool invert = invertedAppearance();
const QSize size = qxt_d().getStarSize();
const QRectF star = qxt_d().star.boundingRect();
painter.scale(size.width() / star.width(), size.height() / star.height());
const int count = maximum() - minimum();
if (orientation() == Qt::Horizontal)
{
painter.translate(-star.x(), -star.y());
if (invert != isRightToLeft())
painter.translate((count - 1) * star.width(), 0);
}
else
{
painter.translate(-star.x(), -star.y());
if (!invert)
painter.translate(0, (count - 1) * star.height());
}
for (int i = 0; i < count; ++i)
{
if (value() > minimum() + i)
painter.setBrush(palette().highlight());
else
painter.setBrush(palette().base());
painter.drawPath(qxt_d().star);
if (orientation() == Qt::Horizontal)
painter.translate(invert != isRightToLeft() ? -star.width() : star.width(), 0);
else
painter.translate(0, invert ? star.height() : -star.height());
}
painter.restore();
if (hasFocus())
{
QStyleOptionFocusRect opt;
opt.initFrom(this);
opt.rect.setSize(sizeHint());
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &painter, this);
}
}
示例12: paintEvent
void Plotter::paintEvent(QPaintEvent * /* event */)
{
QStylePainter painter(this);
painter.drawPixmap(0, 0, pixmap);
if (rubberBandIsShown) {
painter.setPen(palette().light().color());
painter.drawRect(rubberBandRect.normalized().adjusted(0, 0, -1, -1));
}
if (hasFocus()) {
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().dark().color();
painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
}
}
示例13: paintEvent
void StarWidget::paintEvent(QPaintEvent *event)
{
QPainter p(this);
for (int i = 0; i < current; i++)
p.drawPixmap(i * IMG_SIZE + SPACING, 0, starActive());
for (int i = current; i < TOTALSTARS; i++)
p.drawPixmap(i * IMG_SIZE + SPACING, 0, starInactive());
if (hasFocus()) {
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().color(QPalette::Background);
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &p, this);
}
}
示例14: paintEvent
void Plotter::paintEvent(QPaintEvent *pEvent)
{
//Q_UNUSED(pEvent);
QStylePainter painter(this);
QColor l_objColor;
painter.drawPixmap(0,0,pixmap);
if(rubberBandIsShown)
{
painter.setPen(palette().light().color());
painter.setBackgroundMode(Qt::TransparentMode);
painter.fillRect(rubberBandRect,Qt::NoBrush);
painter.drawRect(rubberBandRect.normalized());
}
if(hasFocus())
{
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().dark().color();
painter.drawPrimitive(QStyle::PE_FrameFocusRect,option);
}
}
示例15: paintEvent
void KisAbstractSliderSpinBox::paintEvent(QPaintEvent* e)
{
Q_D(KisAbstractSliderSpinBox);
Q_UNUSED(e)
QPainter painter(this);
//Create options to draw spin box parts
QStyleOptionSpinBox spinOpts = spinBoxOptions();
//Draw "SpinBox".Clip off the area of the lineEdit to avoid double
//borders being drawn
painter.save();
painter.setClipping(true);
QRect eraseRect(QPoint(rect().x(), rect().y()),
QPoint(progressRect(spinOpts).right(), rect().bottom()));
painter.setClipRegion(QRegion(rect()).subtracted(eraseRect));
style()->drawComplexControl(QStyle::CC_SpinBox, &spinOpts, &painter, d->dummySpinBox);
painter.setClipping(false);
painter.restore();
//Create options to draw progress bar parts
QStyleOptionProgressBar progressOpts = progressBarOptions();
//Draw "ProgressBar" in SpinBox
style()->drawControl(QStyle::CE_ProgressBar, &progressOpts, &painter, 0);
//Draw focus if necessary
if (hasFocus() &&
d->edit->hasFocus()) {
QStyleOptionFocusRect focusOpts;
focusOpts.initFrom(this);
focusOpts.rect = progressOpts.rect;
focusOpts.backgroundColor = palette().color(QPalette::Window);
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOpts, &painter, this);
}
}