Unsolved No fill color option
-
I am using following files from https://github.com/liangqi/qt-solutions/tree/master/qtcolorcombobox/src
- qtcolorcombobox.h
- qtcolorcombobox.cpp
I have to enhacnec the code for to have no fill option also . Can some one quide for that
-
Hi
its not clear what
"no fill option "
should do. -
@Qt-Enthusiast Hi! It's not clear to me what you want to achieve. Can you please explain your intentions again, maybe draw a mockup?
-
In color dialoboxes . we also have nofill color option
For example . I have QGrapghicscene , if I have set the fill color of objects as red and I select no fill color m, then set the color of object to background color of QGrapghicscene
-
Oh, I see. I don't think you need extra code for this. Just insert a completely transparent color together with the text "No color" to the combobox.
-
if you could write a code it will be helpful
-
@Qt-Enthusiast said:
if you could write a code it will be helpful
insertColor(0, QColor(0,0,0,0), tr("No color"));
-
should it be like that
void QtColorComboBox::insertColor(int index, const QColor &color, const QString &name)
{
QPixmap pix(12, 12);
QPainter painter(&pix);
if (color.isValid()) {
painter.setPen(Qt::gray);
painter.setBrush(QBrush(Qt::NoBrush));
painter.drawRect(0, 0, 12, 12);
}
QIcon icon;
icon.addPixmap(pix);// Prevent adding of colors after the color dialog item. if (colorDialogEnabled && index > colorCount()) index = colorCount() - 1; insertItem(index, icon, name, color);
}
QColor QtColorComboBox::color(int index) const
{
QVariant var = itemData(index);
// discard out of bounds requests
if (!var.isValid())
return QColor();// discard requests for the "more" item if (colorDialogEnabled && index == colorCount()) return QColor(); return qVariantValue<QColor>(var);
}
-
@Qt-Enthusiast said:
should it be like that [...]
You can leave the widget's sources as they are. No need to customize them. It is just a combobox which can hold a string and a colored rectangle together with some index.