|
|
@@ -1,61 +0,0 @@
|
|
|
-#include <QStylePainter>
|
|
|
-#include "checkableComboBox.h"
|
|
|
-
|
|
|
-CheckableComboBox::CheckableComboBox(QWidget* parent): QComboBox(parent)
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
-void CheckableComboBox::setChecked(bool val)
|
|
|
-{
|
|
|
- if (checked != val)
|
|
|
- {
|
|
|
- checked = val;
|
|
|
- this->update();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-bool CheckableComboBox::isChecked() const
|
|
|
-{
|
|
|
- return checked;
|
|
|
-}
|
|
|
-
|
|
|
-void CheckableComboBox::paintEvent(QPaintEvent* e)
|
|
|
-{
|
|
|
- QStylePainter painter(this);
|
|
|
- painter.setPen(palette().color(QPalette::Text));
|
|
|
- QStyleOptionComboBox opt;
|
|
|
- initStyleOption(&opt);
|
|
|
-
|
|
|
- if (checked)
|
|
|
- {
|
|
|
- QStyleOptionButton option;
|
|
|
- QRectF downButtonRect = style()->proxy()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxArrow, this);
|
|
|
- option.initFrom(this);
|
|
|
- option.features = QStyleOptionButton::HasMenu;
|
|
|
- option.state |= QStyle::State_On;
|
|
|
- option.text = currentText();
|
|
|
- option.icon = qvariant_cast<QIcon>(currentData(Qt::DecorationRole));
|
|
|
- option.iconSize = iconSize();
|
|
|
-
|
|
|
- // Draw button
|
|
|
- option.rect.adjust(0, 0, downButtonRect.width() +4, 0);
|
|
|
- painter.drawControl(QStyle::CE_PushButtonBevel, option);
|
|
|
-
|
|
|
- // Draw button text
|
|
|
- option.rect.adjust(0, 0, -downButtonRect.width() -4, 0);
|
|
|
- painter.drawControl(QStyle::CE_PushButtonLabel, option);
|
|
|
-
|
|
|
- // Draw dropdown button
|
|
|
- painter.setPen(palette().text().color());
|
|
|
- painter.drawText(downButtonRect, "\uE019", Qt::AlignVCenter | Qt::AlignHCenter);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (currentIndex() < 0 && !placeholderText().isEmpty()) {
|
|
|
- opt.palette.setBrush(QPalette::ButtonText, opt.palette.placeholderText());
|
|
|
- opt.currentText = placeholderText();
|
|
|
- }
|
|
|
- painter.drawComplexControl(QStyle::CC_ComboBox, opt);
|
|
|
- painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
|
|
|
- }
|
|
|
-}
|