当前位置: 首页>>代码示例>>C++>>正文


C++ QStyleOptionFrame::initFrom方法代码示例

本文整理汇总了C++中QStyleOptionFrame::initFrom方法的典型用法代码示例。如果您正苦于以下问题:C++ QStyleOptionFrame::initFrom方法的具体用法?C++ QStyleOptionFrame::initFrom怎么用?C++ QStyleOptionFrame::initFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QStyleOptionFrame的用法示例。


在下文中一共展示了QStyleOptionFrame::initFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: paintEvent

void KSelector::paintEvent( QPaintEvent * )
{
  QPainter painter;
  int w = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
  int iw = (w < ARROWSIZE) ? ARROWSIZE : w;

  painter.begin( this );

  drawContents( &painter );

  QBrush brush;

  QPoint pos = calcArrowPos( value() );
  drawArrow( &painter, pos );

  if ( indent() )
  {
    QStyleOptionFrame opt;
    opt.initFrom( this );
    opt.state = QStyle::State_Sunken;
    if ( orientation() == Qt::Vertical )
      opt.rect.adjust( 0, iw - w, -5, w - iw );
    else
      opt.rect.adjust(iw - w, 0, w - iw, -5);
    style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );
  }


  painter.end();
}
开发者ID:FaizaGara,项目名称:lima,代码行数:30,代码来源:kselector.cpp

示例2: updateSizeHint

void MultiLineEdit::updateSizeHint()
{
    QFontMetrics fm(font());
    int minPixelHeight = fm.lineSpacing() * _minHeight;
    int maxPixelHeight = fm.lineSpacing() * _maxHeight;
    int scrollBarHeight = horizontalScrollBar()->isVisible() ? horizontalScrollBar()->height() : 0;

    // use the style to determine a decent size
    int h = qMin(qMax((int)document()->size().height() + scrollBarHeight, minPixelHeight), maxPixelHeight) + 2 * frameWidth();

    QStyleOptionFrame opt;
    opt.initFrom(this);
    opt.rect = QRect(0, 0, 100, h);
    opt.lineWidth = lineWidth();
    opt.midLineWidth = midLineWidth();
    opt.state |= QStyle::State_Sunken;
    QWidget* widget = this;
#ifdef Q_OS_MAC
    widget = 0;
#endif
    QSize s = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(100, h).expandedTo(QApplication::globalStrut()), widget);
    if (s != _sizeHint) {
        _sizeHint = s;
        updateGeometry();
    }
}
开发者ID:fuzzball81,项目名称:quassel,代码行数:26,代码来源:multilineedit.cpp

示例3: paintEvent

void QxtToolTipPrivate::paintEvent(QPaintEvent* event)
{
    Q_UNUSED(event);
    QStylePainter painter(this);
    QStyleOptionFrame opt;
    opt.initFrom(this);
    painter.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
}
开发者ID:edwardoid,项目名称:DarkKnight,代码行数:8,代码来源:qxttooltip.cpp

示例4: paintEvent

void ColorButton::paintEvent(QPaintEvent *ev)
{
	QPushButton::paintEvent(ev);
	QPainter p(this);

	// Get contents rectangle
	QStyleOptionButton opt;
	initStyleOption(&opt);
	QRect cRect;
	if(isFlat()) {
		// Fill the entire widget area
		cRect = rect();
	} else {
		// Only fill the contents area
		cRect =
			style()->subElementRect(QStyle::SE_PushButtonContents, &opt, this);
	}
	cRect.adjust(1, 1, -1, -1); // A little larger padding please

	// Colour fill
	if(m_color.alpha() == 255)
		p.fillRect(cRect, m_color);
	else {
		// Separate left and right rectangles
		QRect lRect = cRect;
		lRect.setWidth(lRect.width() / 2 + 1);
		QRect rRect = cRect;
		rRect.setLeft(lRect.right());

		// Fill the left with the solid colour
		p.fillRect(
			lRect, QColor(m_color.red(), m_color.green(), m_color.blue()));

		// Fill the right with the transparent colour on a checkerboard
		drawCheckerboard(p, rRect, 5, Qt::white, QColor(0xCC, 0xCC, 0xCC));
		p.fillRect(rRect, m_color);
	}

	// Sunken frame
	QStyleOptionFrame fOpt;
	fOpt.initFrom(this);
	fOpt.rect = cRect;
	fOpt.features = QStyleOptionFrame::None;
	fOpt.frameShape = QFrame::Panel;
	fOpt.lineWidth = 1;
	fOpt.midLineWidth = 0;
	fOpt.state |= QStyle::State_Sunken;
	style()->drawControl(QStyle::CE_ShapedFrame, &fOpt, &p, this);

	// Fade out when disabled
	if(!isEnabled()) {
		QBrush brush = palette().base();
		QColor col = brush.color();
		col.setAlpha(127); // 50% transparency
		brush.setColor(col);
		p.fillRect(cRect, brush);
	}
}
开发者ID:andrejsavikin,项目名称:mishira,代码行数:58,代码来源:colorbutton.cpp

示例5: drawStyled

void QwtPlotAbstractCanvas::drawStyled( QPainter *painter, bool hackStyledBackground )
{
    fillBackground( painter );

    if ( hackStyledBackground )
    {
        // Antialiasing rounded borders is done by
        // inserting pixels with colors between the 
        // border color and the color on the canvas,
        // When the border is painted before the plot items
        // these colors are interpolated for the canvas
        // and the plot items need to be clipped excluding
        // the anialiased pixels. In situations, where
        // the plot items fill the area at the rounded
        // borders this is noticeable.
        // The only way to avoid these annoying "artefacts"
        // is to paint the border on top of the plot items.

        if ( !d_data->styleSheet.hasBorder ||
            d_data->styleSheet.borderPath.isEmpty() )
        {
            // We have no border with at least one rounded corner
            hackStyledBackground = false;
        }
    }
    
    QWidget *w = canvasWidget();

    if ( hackStyledBackground )
    {
        painter->save();
        
        // paint background without border
        painter->setPen( Qt::NoPen );
        painter->setBrush( d_data->styleSheet.background.brush );
        painter->setBrushOrigin( d_data->styleSheet.background.origin );
        painter->setClipPath( d_data->styleSheet.borderPath );
        painter->drawRect( w->contentsRect() );

        painter->restore();

        drawCanvas( painter );

        // Now paint the border on top
        QStyleOptionFrame opt;
        opt.initFrom( w );
        w->style()->drawPrimitive( QStyle::PE_Frame, &opt, painter, w);
    }   
    else
    {
        QStyleOption opt;
        opt.initFrom( w );
        w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w );
    
        drawCanvas( painter );
    }   
}   
开发者ID:Au-Zone,项目名称:qwt,代码行数:57,代码来源:qwt_plot_abstract_canvas.cpp

示例6: 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;
  }
开发者ID:wongjimsan,项目名称:QGIS,代码行数:56,代码来源:qgsgradientstopeditor.cpp

示例7: paintEvent

void ComboBox::paintEvent( QPaintEvent * _pe )
{
	QPainter p( this );

	p.fillRect( 2, 2, width()-2, height()-4, *s_background );

	QColor shadow = palette().shadow().color();
	QColor highlight = palette().highlight().color();

	shadow.setAlpha( 124 );
	highlight.setAlpha( 124 );

	// button-separator
	p.setPen( shadow );
	p.drawLine( width() - CB_ARROW_BTN_WIDTH - 1, 1, width() - CB_ARROW_BTN_WIDTH - 1, height() - 3 );

	p.setPen( highlight );
	p.drawLine( width() - CB_ARROW_BTN_WIDTH, 1, width() - CB_ARROW_BTN_WIDTH, height() - 3 );

	// Border
	QStyleOptionFrame opt;
	opt.initFrom( this );
	opt.state = 0;

	style()->drawPrimitive( QStyle::PE_Frame, &opt, &p, this );

	QPixmap * arrow = m_pressed ? s_arrowSelected : s_arrow;

	p.drawPixmap( width() - CB_ARROW_BTN_WIDTH + 5, 4, *arrow );

	if( model() && model()->size() > 0 )
	{
		p.setFont( font() );
		p.setClipRect( QRect( 4, 2, width() - CB_ARROW_BTN_WIDTH - 8, height() - 2 ) );
		QPixmap pm = model()->currentData() ?  model()->currentData()->pixmap() : QPixmap();
		int tx = 5;
		if( !pm.isNull() )
		{
			if( pm.height() > 16 )
			{
				pm = pm.scaledToHeight( 16, Qt::SmoothTransformation );
			}
			p.drawPixmap( tx, 3, pm );
			tx += pm.width() + 3;
		}
		const int y = ( height()+p.fontMetrics().height() ) /2;
		p.setPen( QColor( 64, 64, 64 ) );
		p.drawText( tx+1, y-3, model()->currentText() );
		p.setPen( QColor( 224, 224, 224 ) );
		p.drawText( tx, y-4, model()->currentText() );
	}
}
开发者ID:DanielAeolusLaude,项目名称:lmms,代码行数:52,代码来源:ComboBox.cpp

示例8: paintEvent

void KXYSelector::paintEvent( QPaintEvent * /* ev */ )
{
  QStyleOptionFrame opt;
  opt.initFrom(this);

  QPainter painter;
  painter.begin( this );

  drawContents( &painter );
  drawMarker( &painter, d->px, d->py );

  style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );

  painter.end();
}
开发者ID:crayonink,项目名称:calligra-2,代码行数:15,代码来源:kxyselector.cpp

示例9: paintEvent

void KviThemedComboBox::paintEvent(QPaintEvent * event)
{
#ifdef COMPILE_PSEUDO_TRANSPARENCY
	QPainter * p = new QPainter(this);
	QLineEdit * le = lineEdit();
	if(le)
	{
		QRect r = rect();
		QPalette pal = palette();

		QStyleOptionFrame option;

		option.initFrom(this);
		option.rect = contentsRect();
		option.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, le);
		option.midLineWidth = 0;
		option.state |= QStyle::State_Sunken;
		if(le->isReadOnly())
			option.state |= QStyle::State_ReadOnly;
		option.features = QStyleOptionFrame::None;
		style()->drawPrimitive(QStyle::PE_FrameLineEdit, &option, p, this);

		r = style()->subElementRect(QStyle::SE_LineEditContents, &option, le);
		int left, right, top, bottom;
		le->getTextMargins(&left, &top, &right, &bottom);
		r.setX(r.x() + left);
		r.setY(r.y() + top);
		r.setRight(r.right() - right);
		r.setBottom(r.bottom() - bottom);
		p->setClipRect(r);
	} // else not editable

	if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
	{
		p->setCompositionMode(QPainter::CompositionMode_Source);
		QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
		col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100));
		p->fillRect(contentsRect(), col);
	}
	else if(g_pShadedChildGlobalDesktopBackground)
	{
		QPoint pnt = m_pKviWindow->isDocked() ? mapTo(g_pMainWindow, contentsRect().topLeft()) : mapTo(m_pKviWindow, contentsRect().topLeft());
		p->drawTiledPixmap(contentsRect(), *(g_pShadedChildGlobalDesktopBackground), pnt);
	}
	delete p;
#endif
	QComboBox::paintEvent(event);
}
开发者ID:Dessa,项目名称:KVIrc,代码行数:48,代码来源:KviThemedComboBox.cpp

示例10: paintEvent

void ValueSlider::paintEvent(QPaintEvent *)
{
	QPainter painter(this);
	drawFrame(&painter);
	QRect rectangle = contentsRect();
	QStyleOptionFrame optionFrame;
	optionFrame.initFrom(this);
	if (optionFrame.state & QStyle::State_Enabled)
	{
		painter.drawPixmap(rectangle.topLeft(), pixMap);
		DrawTriangle(&painter, trianglePoint);
	} else {
		QIcon icon(pixMap);
		icon.paint(&painter, rectangle, 0, QIcon::Disabled);
	}
}
开发者ID:atdyer,项目名称:SMT,代码行数:16,代码来源:ValueSlider.cpp

示例11: updateStyledFrameWidths

/*!
  \internal
  Updates the frame widths from the style.
*/
void QFramePrivate::updateStyledFrameWidths()
{
    Q_Q(const QFrame);
    QStyleOptionFrame opt;
    opt.initFrom(q);
    opt.lineWidth = lineWidth;
    opt.midLineWidth = midLineWidth;
    opt.frameShape = QFrame::Shape(frameStyle & QFrame::Shape_Mask);

    QRect cr = q->style()->subElementRect(QStyle::SE_ShapedFrameContents, &opt, q);
    leftFrameWidth = cr.left() - opt.rect.left();
    topFrameWidth = cr.top() - opt.rect.top();
    rightFrameWidth = opt.rect.right() - cr.right(),
    bottomFrameWidth = opt.rect.bottom() - cr.bottom();
    frameWidth = qMax(qMax(leftFrameWidth, rightFrameWidth),
                      qMax(topFrameWidth, bottomFrameWidth));
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:21,代码来源:qframe.cpp

示例12: borderMask

/*!
   Calculate a mask, that can be used to clip away the border frame

   \param size Size including the frame
*/
QBitmap QwtPlotCanvas::borderMask( const QSize &size ) const
{
    const QRect r( 0, 0, size.width(), size.height() );

    const QPainterPath path = borderPath( r );
    if ( path.isEmpty() )
        return QBitmap();

    QImage image( size, QImage::Format_ARGB32_Premultiplied );
    image.fill( Qt::color0 );

    QPainter painter( &image );
    painter.setClipPath( path );
    painter.fillRect( r, Qt::color1 );

    // now erase the frame

    painter.setCompositionMode( QPainter::CompositionMode_DestinationOut );

    if ( testAttribute(Qt::WA_StyledBackground ) )
    {
        QStyleOptionFrame opt;
        opt.initFrom(this);
        opt.rect = r;
        style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );
    }
    else
    {
        if ( d_data->borderRadius > 0 && frameWidth() > 0 )
        {
            painter.setPen( QPen( Qt::color1, frameWidth() ) );
            painter.setBrush( Qt::NoBrush );
            painter.setRenderHint( QPainter::Antialiasing, true );

            painter.drawPath( path );
        }
    }

    painter.end();

    const QImage mask = image.createMaskFromColor(
        QColor( Qt::color1 ).rgb(), Qt::MaskOutColor );

    return QBitmap::fromImage( mask );
}
开发者ID:Alex-Rongzhen-Huang,项目名称:OpenPilot,代码行数:50,代码来源:qwt_plot_canvas.cpp

示例13: paint

void ColorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                           const QModelIndex &index) const
{
    if (index.data().canConvert<QColor>())
    {
        QStyleOptionFrame panel;
        panel.initFrom(option.widget);
        if (option.widget->isEnabled())
            panel.state = QStyle::State_Enabled;
        panel.rect = option.rect;
        panel.lineWidth = 2;
        panel.midLineWidth = 0;
        panel.state |= QStyle::State_Sunken;
        option.widget->style()->drawPrimitive(QStyle::PE_Frame, &panel, painter, nullptr);
        QRect r = option.widget->style()->subElementRect(QStyle::SE_FrameContents, &panel, nullptr);
        painter->setClipRect(r);
        painter->fillRect(option.rect, index.data().value<QColor>());
    }
}
开发者ID:ensisoft,项目名称:opengl-sample-app,代码行数:19,代码来源:color_delegate.cpp

示例14: paintEvent

/*!
 * \internal
 */
void HacLed::paintEvent(QPaintEvent * )
{
    QPainter p(this);
    QColor bgColor = palette().background().color();

    if (d->shape==Circular) {
        int sidesize = qMin(width(), height());
        p.setRenderHint(QPainter::Antialiasing);
        int rad = sidesize*0.45;
        QRect r = rect().adjusted((width()-sidesize)/2, (height()-sidesize)/2, -(width()-sidesize)/2, -(height()-sidesize)/2);
        QRadialGradient grad(rect().center(), rad, rect().center()-QPoint(sidesize*0.1, sidesize*0.1) );
        grad.setColorAt(0.0, palette().color(QPalette::Light));
        grad.setColorAt(0.75, isChecked() ? d->color : bgColor);
        p.setBrush(grad);
        QPen pe = p.pen();
        pe.setWidth(d->width);
        pe.setColor(palette().color(QPalette::Foreground));
        p.setPen(pe);

        p.drawEllipse(r.adjusted(d->width,d->width,-d->width,-d->width));
    } else { /*if (d->shape == Rectangular)*/
        QStyleOptionFrame opt;
        opt.initFrom(this);
        opt.lineWidth = d->width;
        opt.midLineWidth = d->width;
        if (d->shape==RectangularRaised)
            opt.state |= QStyle::State_Raised;
        else if (d->shape==RectangularSunken)
            opt.state |= QStyle::State_Sunken;
        QBrush br(isChecked() ? d->color : bgColor);
        if (d->shape==RectangularPlain)
            qDrawPlainRect(&p, opt.rect, opt.palette.foreground().color(), d->width, &br);
        else
            qDrawShadePanel(&p, opt.rect, opt.palette, d->shape==RectangularSunken, d->width, &br);
    }
}
开发者ID:etop-wesley,项目名称:hac,代码行数:39,代码来源:hacled.cpp

示例15: paintEvent

void Swatch::paintEvent(QPaintEvent* event)
{
    QSize rowcols = p->rowcols();
    if ( rowcols.isEmpty() )
        return;

    QSizeF color_size = p->actualColorSize(rowcols);
    QPixmap alpha_pattern(detail::alpha_pixmap());
    QPen penEmptyBorder = p->border;
    QColor colorEmptyBorder = p->border.color();
    colorEmptyBorder.setAlpha(56);
    penEmptyBorder.setColor(colorEmptyBorder);
    QPainter painter(this);

    QStyleOptionFrame panel;
    panel.initFrom(this);
    panel.lineWidth = 1;
    panel.midLineWidth = 0;
    panel.state |= QStyle::State_Sunken;
    style()->drawPrimitive(QStyle::PE_Frame, &panel, &painter, this);
    QRect r = style()->subElementRect(QStyle::SE_FrameContents, &panel, this);
    painter.setClipRect(r);

    int count = p->palette.count();
        painter.setPen(p->border);
    for ( int y = 0, i = 0; i < count; y++ )
    {
        for ( int x = 0; x < rowcols.width() && i < count; x++, i++ )
        {
            if(p->palette.colorAt(i) == p->emptyColor)
            {
              painter.setBrush(Qt::NoBrush);
              painter.setPen(penEmptyBorder);
              painter.drawRect(p->indexRect(i, rowcols, color_size));
              continue;
            }
            painter.setBrush(alpha_pattern);
            painter.drawRect(p->indexRect(i, rowcols, color_size));
            painter.setBrush(p->palette.colorAt(i));
            painter.drawRect(p->indexRect(i, rowcols, color_size));
        }
    }

    painter.setClipping(false);

    if ( p->drop_index != -1 )
    {
        QRectF drop_area = p->indexRect(p->drop_index, rowcols, color_size);
        if ( p->drop_overwrite )
        {
            painter.setBrush(p->drop_color);
            painter.setPen(QPen(Qt::gray));
            painter.drawRect(drop_area);
        }
        else if ( rowcols.width() == 1 )
        {
            // 1 column => vertical style
            painter.setPen(QPen(p->drop_color, 2));
            painter.setBrush(Qt::transparent);
            painter.drawLine(drop_area.topLeft(), drop_area.topRight());
        }
        else
        {
            painter.setPen(QPen(p->drop_color, 2));
            painter.setBrush(Qt::transparent);
            painter.drawLine(drop_area.topLeft(), drop_area.bottomLeft());
            // Draw also on the previous line when the first item of a line is selected
            if ( p->drop_index % rowcols.width() == 0 && p->drop_index != 0 )
            {
                drop_area = p->indexRect(p->drop_index-1, rowcols, color_size);
                drop_area.translate(color_size.width(), 0);
                painter.drawLine(drop_area.topLeft(), drop_area.bottomLeft());
            }
        }
    }

    if ( p->selected != -1 )
    {
        QRectF rect = p->indexRect(p->selected, rowcols, color_size);
        painter.setBrush(Qt::transparent);
        painter.setPen(QPen(Qt::darkGray, 2));
        painter.drawRect(rect);
        painter.setPen(p->selection);
        painter.drawRect(rect);
    }
}
开发者ID:jcelerier,项目名称:Qt-Color-Widgets,代码行数:86,代码来源:swatch.cpp


注:本文中的QStyleOptionFrame::initFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。