本文整理汇总了C++中QColor::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ QColor::isValid方法的具体用法?C++ QColor::isValid怎么用?C++ QColor::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QColor
的用法示例。
在下文中一共展示了QColor::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mouseReleaseEvent
void SeExprEdColorFrame::mouseReleaseEvent(QMouseEvent* event)
{
if (event->button() == Qt::RightButton)
deleteSwatchMenu(event->pos());
else {
#ifdef SEEXPR_USE_QDGUI
QColor color = QdColorPickerDialog::chooseColorFromDialog(_color,this);
#else
QColor color = QColorDialog::getColor(_color);
#endif
if (color.isValid()) {
_value[0] = color.red() / 255.0;
_value[1] = color.green() / 255.0;
_value[2] = color.blue() / 255.0;
update();
_color = color;
emit selValChangedSignal(_value);
emit swatchChanged(color);
}
}
}
示例2: onChooseColor
/**
* Opens a QColorDialog to set a new color.
*/
void ColorButton::onChooseColor()
{
if (!d->allowChange)
return;
if (d->modal) {
QColor c = QColorDialog::getColor(d->col, this);
if (c.isValid()) {
setColor(c);
changed();
}
}
else {
if (d->cd.isNull()) {
d->old = d->col;
d->cd = new QColorDialog(d->col, this);
d->cd->setAttribute(Qt::WA_DeleteOnClose);
connect(d->cd, SIGNAL(rejected()),
this, SLOT(onRejected()));
connect(d->cd, SIGNAL(currentColorChanged(const QColor &)),
this, SLOT(onColorChosen(const QColor&)));
}
d->cd->show();
}
示例3: setThemeColor
/**
* @brief Set theme color.
* @param color Color to set.
*
* Pass an invalid QColor to reset to defaults.
*/
void Style::setThemeColor(const QColor &color)
{
if (!color.isValid())
{
// Reset to default
palette[ThemeDark] = QColor("#1c1c1c");
palette[ThemeMediumDark] = QColor("#2a2a2a");
palette[ThemeMedium] = QColor("#414141");
palette[ThemeLight] = QColor("#4e4e4e");
}
else
{
palette[ThemeDark] = color.darker(155);
palette[ThemeMediumDark] = color.darker(135);
palette[ThemeMedium] = color.darker(120);
palette[ThemeLight] = color.lighter(110);
}
dict["@themeDark"] = getColor(ThemeDark).name();
dict["@themeMediumDark"] = getColor(ThemeMediumDark).name();
dict["@themeMedium"] = getColor(ThemeMedium).name();
dict["@themeLight"] = getColor(ThemeLight).name();
}
示例4: tagColorChanged
void
TagColorEditor::cellDoubleClicked(int row, int col)
{
QTableWidgetItem *item = table->item(row, col);
uchar *colors = Global::tagColors();
int index = row*2 + col;
QColor clr = QColor(colors[4*index+0],
colors[4*index+1],
colors[4*index+2]);
clr = DColorDialog::getColor(clr);
if (!clr.isValid())
return;
colors[4*index+0] = clr.red();
colors[4*index+1] = clr.green();
colors[4*index+2] = clr.blue();
item->setData(Qt::DisplayRole, QString("%1").arg(index));
item->setBackground(clr);
emit tagColorChanged();
}
示例5: entryTextChanged
void
ColourTable::slotEditEntry(int row, int col)
{
switch (col) {
case 0: {
if (row == 0)
return ;
bool ok = false;
QString newName = InputDialog::getText(this,
tr("Modify Color Name"),
tr("Enter new name"),
LineEdit::Normal,
item(row, col)->text(), &ok);
if ((ok == true) && (!newName.isEmpty())) {
emit entryTextChanged(row, newName);
return ;
}
}
break;
case 1: {
QColor temp = m_colours[row];
QColor result = QColorDialog::getColor(temp);
if (result.isValid()) {
emit entryColourChanged(row, temp);
return ;
}
}
break;
default: // Should never happen
break;
}
}
示例6: editorEvent
bool QmitkDoseColorDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
const QModelIndex &index)
{
Q_ASSERT(event);
Q_ASSERT(model);
// make sure that the item is checkable
Qt::ItemFlags flags = model->flags(index);
if (!(flags & Qt::ItemIsEditable) || !(flags & Qt::ItemIsEnabled))
{
return false;
}
// make sure that we have the right event type
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
if (!mouseEvent)
{
return false;
}
else
{
if (mouseEvent->type() != QEvent::MouseButtonRelease || mouseEvent->button() != Qt::LeftButton)
{
return false;
}
}
QColor oldcolor = index.data(Qt::EditRole).value<QColor>();
QColor newColor = QColorDialog::getColor(oldcolor, NULL);
if (newColor.isValid())
{
return model->setData(index, QVariant(newColor), Qt::EditRole);
}
return false;
};
示例7: paintEvent
void ColorButton::paintEvent( QPaintEvent * )
{
QPainter painter(this);
//First, we need to draw the bevel.
QStyleOptionButton butOpt;
initStyleOption(&butOpt);
style()->drawControl( QStyle::CE_PushButtonBevel, &butOpt, &painter, this );
//OK, now we can muck around with drawing out pretty little color box
//First, sort out where it goes
QRect labelRect = style()->subElementRect( QStyle::SE_PushButtonContents,
&butOpt, this );
int shift = style()->pixelMetric( QStyle::PM_ButtonMargin );
labelRect.adjust(shift, shift, -shift, -shift);
int x, y, w, h;
labelRect.getRect(&x, &y, &w, &h);
if (isChecked() || isDown()) {
x += style()->pixelMetric( QStyle::PM_ButtonShiftHorizontal );
y += style()->pixelMetric( QStyle::PM_ButtonShiftVertical );
}
QColor fillCol = isEnabled() ? btnColor : palette().color(backgroundRole());
qDrawShadePanel( &painter, x, y, w, h, palette(), true, 1, NULL);
if ( fillCol.isValid() )
painter.fillRect( x+1, y+1, w-2, h-2, fillCol );
if ( hasFocus() ) {
QRect focusRect = style()->subElementRect( QStyle::SE_PushButtonFocusRect, &butOpt, this );
QStyleOptionFocusRect focusOpt;
focusOpt.init(this);
focusOpt.rect = focusRect;
focusOpt.backgroundColor = palette().background().color();
style()->drawPrimitive( QStyle::PE_FrameFocusRect, &focusOpt, &painter, this );
}
}
示例8: eventFilter
bool PreferencesDialog::eventFilter(QObject *obj, QEvent *event)
{
// Use mouse click and enter press on the frames to pop up a colour dialog
if (obj == ui->frameNullBgColour || obj == ui->frameNullFgColour)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *key = static_cast<QKeyEvent *>(event);
// Not interesting, so send to the parent (might be shortcuts)
if((key->key() != Qt::Key_Enter) && (key->key() != Qt::Key_Return))
{
return QDialog::eventFilter(obj, event);
}
}
else if (event->type() != QEvent::MouseButtonPress)
{
// Not a key event neither a mouse event, send to the parent
return QDialog::eventFilter(obj, event);
}
QFrame *frame = qobject_cast<QFrame *>(obj);
QColor oldColour = frame->palette().color(frame->backgroundRole());
QColor colour = QColorDialog::getColor(oldColour, frame);
if (colour.isValid())
{
QPalette palette = frame->palette();
palette.setColor(frame->backgroundRole(), colour);
frame->setPalette(palette);
}
// Consume
return true;
}
// Send any other events to the parent
return QDialog::eventFilter(obj, event);
}
示例9: getColor
QColor DomConvenience::getColor(const QDomElement& e)
{
QColor color;
if (e.hasAttribute("name"))
color = QColor(e.attribute("name"));
// allow specifying of base color by name and then tweaking
if (e.hasAttribute("red") ||
e.hasAttribute("green") ||
e.hasAttribute("blue"))
{
int base = getBase(e);
bool colorOk = false;
// default to black
int r = 0, g = 0, b = 0;
// if color was specified by name, use it's RGB values as defaults
if (color.isValid())
{
r = color.red();
g = color.green();
b = color.blue();
}
if (e.hasAttribute("red"))
r = e.attribute("red").toInt(&colorOk, base);
if (e.hasAttribute("green"))
g = e.attribute("green").toInt(&colorOk, base);
if (e.hasAttribute("blue"))
b = e.attribute("blue").toInt(&colorOk, base);
color = QColor(r, g, b);
}
return color;
}
示例10: xColorFromVariant
xColor xColorFromVariant(const QVariant &object, bool& isValid) {
isValid = false;
xColor color { 0, 0, 0 };
if (!object.isValid()) {
return color;
}
if (object.canConvert<int>()) {
isValid = true;
color.red = color.green = color.blue = (uint8_t)object.toInt();
} else if (object.canConvert<QString>()) {
QColor qcolor(object.toString());
if (qcolor.isValid()) {
isValid = true;
color.red = (uint8_t)qcolor.red();
color.blue = (uint8_t)qcolor.blue();
color.green = (uint8_t)qcolor.green();
}
} else if (object.canConvert<QColor>()) {
QColor qcolor = qvariant_cast<QColor>(object);
if (qcolor.isValid()) {
isValid = true;
color.red = (uint8_t)qcolor.red();
color.blue = (uint8_t)qcolor.blue();
color.green = (uint8_t)qcolor.green();
}
} else {
QVariantMap map = object.toMap();
color.red = map["red"].toInt(&isValid);
if (isValid) {
color.green = map["green"].toInt(&isValid);
}
if (isValid) {
color.blue = map["blue"].toInt(&isValid);
}
}
return color;
}
示例11: shade
bool QgsColorRampShader::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
{
//Get the shaded value from the cache if it exists already
QColor myColor = mColorCache.value( theValue );
if ( myColor.isValid() )
{
*theReturnRedValue = myColor.red();
*theReturnGreenValue = myColor.green();
*theReturnBlueValue = myColor.blue();
return true;
}
//pixel value not in cache so generate new value
//Check to be sure mCurrentColorRampItemIndex is within the valid range.
if ( mCurrentColorRampItemIndex < 0 )
{
mCurrentColorRampItemIndex = 0;
}
else if ( mCurrentColorRampItemIndex >= mColorRampItemList.size() )
{
mCurrentColorRampItemIndex = mColorRampItemList.size() - 1;
}
if ( QgsColorRampShader::EXACT == mColorRampType )
{
return exactColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue );
}
else if ( QgsColorRampShader::INTERPOLATED == mColorRampType )
{
return interpolatedColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue );
}
return discreteColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue );
}
示例12: on_mReliefClassTreeWidget_itemDoubleClicked
void QgsRasterTerrainAnalysisDialog::on_mReliefClassTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column )
{
if ( !item )
{
return;
}
if ( column == 0 )
{
bool ok;
double d = QInputDialog::getDouble( 0, tr( "Enter lower elevation class bound" ), tr( "Elevation" ), item->text( 0 ).toDouble(), -2147483647,
2147483647, 2, &ok );
if ( ok )
{
item->setText( 0, QString::number( d ) );
}
}
else if ( column == 1 )
{
bool ok;
double d = QInputDialog::getDouble( 0, tr( "Enter upper elevation class bound" ), tr( "Elevation" ), item->text( 1 ).toDouble(), -2147483647,
2147483647, 2, &ok );
if ( ok )
{
item->setText( 1, QString::number( d ) );
}
}
else if ( column == 2 )
{
QColor c = QColorDialog::getColor( item->background( 2 ).color(), 0, tr( "Select color for relief class" ) );
if ( c.isValid() )
{
item->setBackground( 2, QBrush( c ) );
}
}
}
示例13: mButtonAddColor_clicked
void QgsPresetColorRampWidget::mButtonAddColor_clicked()
{
if ( dockMode() )
{
mTreeColors->addColor( QgsRecentColorScheme::lastUsedColor(), QgsSymbolLayerUtils::colorToName( QgsRecentColorScheme::lastUsedColor() ), true );
QgsCompoundColorWidget *colorWidget = new QgsCompoundColorWidget( this, QgsRecentColorScheme::lastUsedColor(), QgsCompoundColorWidget::LayoutVertical );
colorWidget->setPanelTitle( tr( "Select Color" ) );
colorWidget->setAllowOpacity( true );
connect( colorWidget, &QgsCompoundColorWidget::currentColorChanged, this, &QgsPresetColorRampWidget::newColorChanged );
openPanel( colorWidget );
}
else
{
QColor newColor = QgsColorDialog::getColor( QColor(), this->parentWidget(), tr( "Select Color" ), true );
if ( !newColor.isValid() )
{
return;
}
activateWindow();
mTreeColors->addColor( newColor, QgsSymbolLayerUtils::colorToName( newColor ) );
}
}
示例14: parseColorGroup
/*!
\internal
*/
void QThemeWidgetItem::parseColorGroup(const QMap<QString,QString> &cgatts)
{
if (!d->proxy || !d->proxy->widget())
return;
QPalette pal = d->proxy->palette();
for (int i = 0; colorTable[i].role != QPalette::NColorRoles; ++i)
{
const QString curColorName = QString(colorTable[i].name).toLower();
QColor colour;
for (QMap<QString,QString>::ConstIterator it = cgatts.begin(); it != cgatts.end(); ++it)
{
if (it.key().toLower() == curColorName) {
colour = colorFromString(*it);
break;
}
}
if (colour.isValid()) {
pal.setColor(QPalette::Active, colorTable[i].role, colour);
pal.setColor(QPalette::Inactive, colorTable[i].role, colour);
pal.setColor(QPalette::Disabled, colorTable[i].role, colour);
}
}
d->proxy->setPalette(pal);
}
示例15: selectClearColor
/*
========================
selectClearColor
brings up a color selection dialog for glClearColor.
========================
*/
void CSceneWidget::selectClearColor( bool )
{
QPalette pal = m_btnClearColor->palette();
// ask for new color
QColor color = pal.color( QPalette::Button );
color = QColorDialog::getColor( color, this );
if( color.isValid() )
{
pal.setColor( QPalette::Button, color );
m_btnClearColor->setPalette( pal );
// translate color
vec4_t v(
float(color.red()) / 255.0f,
float(color.green()) / 255.0f,
float(color.blue()) / 255.0f,
1.0f );
// update state
m_scene->setClearColor( v );
}
}