本文整理汇总了C++中QWidget::backgroundRole方法的典型用法代码示例。如果您正苦于以下问题:C++ QWidget::backgroundRole方法的具体用法?C++ QWidget::backgroundRole怎么用?C++ QWidget::backgroundRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWidget
的用法示例。
在下文中一共展示了QWidget::backgroundRole方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventFilter
bool QChildWidget::eventFilter(QObject *o, QEvent *e)
{
if (e->type() == QEvent::Paint){
QWidget *w = static_cast<QWidget*>(o);
for (QWidget *p = parentWidget(); p; p = p->parentWidget()){
const QPixmap bg = p->palette().brush(p->backgroundRole()).texture();
if (!bg.isNull()){
QPoint pos = w->mapToGlobal(QPoint(0, 0));
pos = p->mapFromGlobal(pos);
QRect rc(pos.x(), pos.y(), w->width(), w->height());
if (rc != rcChild){
rcChild = rc;
QPixmap new_bg(w->width(), w->height());
QPainter pp(&new_bg);
pp.drawTiledPixmap(0, 0, w->width(), w->height(), bg, pos.x(), pos.y());
pp.end();
QPalette palette = w->palette();
palette.setBrush(w->backgroundRole(), QBrush(new_bg));
w->setPalette(palette);
}
if (!w->palette().brush(w->backgroundRole()).texture().isNull()){
QPainter pp(w);
pp.drawPixmap(0, 0, w->palette().brush(w->backgroundRole()).texture());
}
return true;
}
}
}
return false;
}
示例2: highlight
void WidgetMain::highlight(WidgetMain::HighlightState state)
{
static QColor defaultColor = palette().color(backgroundRole());
QWidget *w = d_widgetConfigTransmission;
switch (state)
{
case Connected:
case Normal:
{
QPalette p(w->palette());
p.setColor(w->backgroundRole(), QColor("#c5ffa0"));
w->setPalette(p);
break;
}
case Disconnected:
{
QPalette p(w->palette());
p.setColor(w->backgroundRole(), defaultColor);
w->setPalette(p);
break;
}
case Error:
{
QPalette p(w->palette());
p.setColor(w->backgroundRole(), QColor("#ff9595"));
w->setPalette(p);
break;
}
}
}
示例3: backgroundRole
int QWidgetProto::backgroundRole() const
{
QWidget *item = qscriptvalue_cast<QWidget*>(thisObject());
if (item)
return item->backgroundRole();
return 0;
}
示例4: paintEvent
void DJToolButton::paintEvent( QPaintEvent *event )
{
QWidget *parentWidget = qobject_cast<QWidget*>(parent());
if ( parentWidget ) {
QPalette::ColorRole parentRole = parentWidget->backgroundRole();
QPalette parentPalette = parentWidget->palette();
//QRect rect = parentWidget->rect();
QBrush parentBrush = parentPalette.brush( parentRole );
//QPixmap parentPix(prect.width(),prect.height());
//QPainter p(&pix);
//p.fillRect(0,0,pix.width(),pix.height(),parentbrush);
QPalette pal = palette();
pal.setBrush(QPalette::Button,parentBrush);
setPalette(pal);
}
//QRect qrect = tbw->geometry();
// QRect prect = parent->rect();
/*
QPalette pal = palette();
//pal.setBrush(QPalette::Background,Qt::red);
pal.setBrush(QPalette::Button,Qt::green);
//pal.setBrush(QPalette::Base,Qt::blue);
setPalette(pal);
*/
QToolButton::paintEvent( event );
}
示例5: drawBackground
/*!
Draw the background of the canvas
\param painter Painter
*/
void QwtPlotGLCanvas::drawBackground( QPainter *painter )
{
painter->save();
QWidget *w = qwtBGWidget( this );
const QPoint off = mapTo( w, QPoint() );
painter->translate( -off );
const QRect fillRect = rect().translated( off );
if ( w->testAttribute( Qt::WA_StyledBackground ) )
{
painter->setClipRect( fillRect );
QStyleOption opt;
opt.initFrom( w );
w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w);
}
else
{
painter->fillRect( fillRect,
w->palette().brush( w->backgroundRole() ) );
}
painter->restore();
}
示例6: QWidget
ContextView::ContextView( QWidget* parent, const QString& caption )
: QWidget( parent )
, m_trackView( new TrackView() )
, m_temporary( false )
{
TrackItemDelegate* del = new TrackItemDelegate( TrackItemDelegate::LovedTracks, m_trackView, m_trackView->proxyModel() );
m_trackView->setPlaylistItemDelegate( del );
m_trackView->proxyModel()->setStyle( PlayableProxyModel::SingleColumn );
m_trackView->setStyleSheet( QString( "QTreeView { background-color: %1; }" ).arg( TomahawkStyle::PAGE_BACKGROUND.name() ) );
#ifndef Q_OS_MAC
TomahawkStyle::styleScrollBar( m_trackView->verticalScrollBar() );
#endif
setLayout( new QVBoxLayout() );
TomahawkUtils::unmarginLayout( layout() );
m_captionLabel = new CaptionLabel( this );
setCaption( caption );
QWidget* vbox = new QWidget;
QPalette pal = vbox->palette();
pal.setBrush( vbox->backgroundRole(), TomahawkStyle::PAGE_BACKGROUND );
vbox->setPalette( pal );
vbox->setAutoFillBackground( true );
QVBoxLayout* vboxl = new QVBoxLayout();
TomahawkUtils::unmarginLayout( vboxl );
vboxl->setContentsMargins( 32, 32, 32, 32 );
vboxl->setSpacing( 32 );
vbox->setLayout( vboxl );
QWidget* hbox = new QWidget;
QHBoxLayout* hboxl = new QHBoxLayout();
TomahawkUtils::unmarginLayout( hboxl );
hboxl->setSpacing( 32 );
m_innerLayout = new QVBoxLayout();
TomahawkUtils::unmarginLayout( m_innerLayout );
m_innerLayout->addWidget( m_trackView, 1 );
m_innerLayout->addStretch();
m_detailView = new TrackDetailView;
m_detailView->setPlaylistInterface( playlistInterface() );
hboxl->addWidget( m_detailView );
hboxl->addLayout( m_innerLayout );
hbox->setLayout( hboxl );
vboxl->addWidget( m_captionLabel );
vboxl->addWidget( hbox );
layout()->addWidget( vbox );
connect( m_captionLabel, SIGNAL( clicked() ), SIGNAL( closeClicked() ) );
connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), SLOT( onQuerySelected( Tomahawk::query_ptr ) ) );
connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), m_detailView, SLOT( setQuery( Tomahawk::query_ptr ) ) );
connect( m_trackView, SIGNAL( modelChanged() ), SLOT( onModelChanged() ) );
TomahawkUtils::fixMargins( this );
}
示例7: blitToScreen
/*
Should we require that q is a toplevel window ???
Used by QWSManager
*/
void QWidgetPrivate::blitToScreen(const QRegion &globalrgn)
{
Q_Q(QWidget);
QWidget *win = q->window();
QBrush bgBrush = win->palette().brush(win->backgroundRole());
bool opaque = bgBrush.style() == Qt::NoBrush || bgBrush.isOpaque();
QWidget::qwsDisplay()->repaintRegion(win->data->winid, win->windowFlags(), opaque, globalrgn);
}
示例8: setCalendarColor
void ServiceBlock::setCalendarColor(QCalendarWidget *calendarWidget,QColor color)
{
QWidget *calendarNavBar = calendarWidget->findChild<QWidget *>("qt_calendar_navigationbar");
if (calendarNavBar) {
QPalette pal = calendarNavBar->palette();
pal.setColor(calendarNavBar->backgroundRole(), color);
calendarNavBar->setPalette(pal);
}
}
示例9: updateColor
void RKInput::updateColor () {
RK_TRACE (PLUGIN);
QWidget *widget = lineedit;
if (!widget) widget = textedit;
RK_ASSERT (widget);
QPalette palette = widget->palette ();
if (isEnabled ()) {
if (isSatisfied ()) {
palette.setColor (widget->backgroundRole (), QColor (255, 255, 255));
} else {
palette.setColor (widget->backgroundRole (), QColor (255, 0, 0));
}
} else {
palette.setColor (widget->backgroundRole (), QColor (200, 200, 200));
}
widget->setPalette (palette);
}
示例10: initViewPalette
static void initViewPalette(QAbstractItemView* view, const QColor& fgColor)
{
QWidget* viewport = view->viewport();
QPalette palette = viewport->palette();
palette.setColor(viewport->backgroundRole(), Qt::transparent);
palette.setColor(QPalette::WindowText, fgColor);
palette.setColor(QPalette::Text, fgColor);
// QListView uses QStyledItemDelegate, which uses the view palette for
// foreground color, while KFilePlacesView uses the viewport palette.
viewport->setPalette(palette);
view->setPalette(palette);
}
示例11: QWidget
CalamaresWindow::CalamaresWindow( QWidget* parent )
: QWidget( parent )
{
// Hide close button
setWindowFlags( Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint );
setMinimumSize( 1010, 560 );
QSize availableSize = qApp->desktop()->screenGeometry( this ).size();
int w = qBound( 1010, CalamaresUtils::defaultFontHeight() * 60, availableSize.width() );
int h = qBound( 560, CalamaresUtils::defaultFontHeight() * 36, availableSize.height() );
cDebug() << "Proposed window size:" << w << h;
resize( w, h );
QBoxLayout* mainLayout = new QHBoxLayout;
setLayout( mainLayout );
QWidget* sideBox = new QWidget( this );
mainLayout->addWidget( sideBox );
QBoxLayout* sideLayout = new QVBoxLayout;
sideBox->setLayout( sideLayout );
sideBox->setFixedWidth( qMax( 190, CalamaresUtils::defaultFontHeight() * 12 ) );
sideBox->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
QHBoxLayout* logoLayout = new QHBoxLayout;
sideLayout->addLayout( logoLayout );
logoLayout->addStretch();
QLabel* logoLabel = new QLabel( "branding\ngoes\nhere", sideBox );
{
QPalette plt = sideBox->palette();
sideBox->setAutoFillBackground( true );
plt.setColor( sideBox->backgroundRole(), CalamaresStyle::SIDEBAR_BACKGROUND );
plt.setColor( sideBox->foregroundRole(), CalamaresStyle::SIDEBAR_TEXT );
sideBox->setPalette( plt );
logoLabel->setPalette( plt );
}
logoLabel->setAlignment( Qt::AlignCenter );
logoLabel->setFixedSize( 80, 80 );
logoLayout->addWidget( logoLabel );
logoLayout->addStretch();
ProgressTreeView* tv = new ProgressTreeView( sideBox );
sideLayout->addWidget( tv );
CalamaresUtils::unmarginLayout( sideLayout );
CalamaresUtils::unmarginLayout( mainLayout );
Calamares::ViewManager* vm = new Calamares::ViewManager( this );
mainLayout->addWidget( vm->centralWidget() );
}
示例12: on_buttonBackground_clicked
void AmbientProperties::on_buttonBackground_clicked()
{
QColor c = QColorDialog::getColor(backSample->palette().color(backSample->backgroundRole()), this);
QPalette p = backSample->palette(); p.setColor(backSample->backgroundRole(), c); backSample->setPalette(p);
p = container->palette(); p.setColor(container->backgroundRole(), c); container->setPalette(p);
if (QWorkspace *ws = qobject_cast<QWorkspace*>(container)) {
QWidgetList list( ws->windowList() );
for (int i = 0; i < list.count(); ++i) {
QWidget *widget = list.at(i);
p = widget->palette(); p.setColor(widget->backgroundRole(), c); widget->setPalette(p);
}
}
}
示例13: paintEvent
void QChildWidget::paintEvent(QPaintEvent*)
{
for (QWidget *p = parentWidget(); p; p = p->parentWidget()){
const QPixmap bg = p->palette().brush(p->backgroundRole()).texture();
if (!bg.isNull()){
QPoint pos = mapToGlobal(QPoint(0, 0));
pos = p->mapFromGlobal(pos);
QPainter pp(this);
pp.drawTiledPixmap(0, 0, width(), height(), bg, pos.x(), pos.y());
return;
}
if (p == topLevelWidget())
break;
}
QPainter pp(this);
pp.eraseRect(0, 0, width(), height());
}
示例14: main
int main(int argv, char **args)
{
QApplication app(argv, args);
//! [0]
gradient = QRadialGradient gradient(50, 50, 50, 50, 50)
gradient.setColorAt(0, QColor.fromRgbF(0, 1, 0, 1))
gradient.setColorAt(1, QColor.fromRgbF(0, 0, 0, 0))
brush = QBrush(gradient)
//! [0]
QWidget widget;
QPalette palette;
palette.setBrush(widget.backgroundRole(), brush);
widget.setPalette(palette);
widget.show();
return app.exec();
}
示例15: drawUnstyled
void QwtPlotAbstractCanvas::drawUnstyled( QPainter *painter )
{
fillBackground( painter );
QWidget *w = canvasWidget();
if ( w->autoFillBackground() )
{
const QRect canvasRect = w->rect();
painter->save();
painter->setPen( Qt::NoPen );
painter->setBrush( w->palette().brush( w->backgroundRole() ) );
const QRect frameRect = w->property( "frameRect" ).toRect();
if ( borderRadius() > 0.0 && ( canvasRect == frameRect ) )
{
const int frameWidth = w->property( "frameWidth" ).toInt();
if ( frameWidth > 0 )
{
painter->setClipPath( borderPath2( canvasRect ) );
painter->drawRect( canvasRect );
}
else
{
painter->setRenderHint( QPainter::Antialiasing, true );
painter->drawPath( borderPath2( canvasRect ) );
}
}
else
{
painter->drawRect( canvasRect );
}
painter->restore();
}
drawCanvas( painter );
}