12 #include <QApplication>
13 #include <QCoreApplication>
23 popframe_(
NULL, Qt::Popup)
29 vlist_.setSelectionMode(QAbstractItemView::MultiSelection);
30 vlist_.setSelectionBehavior(QAbstractItemView::SelectItems);
34 popframe_.layout()->setContentsMargins(0,0,0,0);
50 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
51 const int textWidth = fontMetrics().horizontalAdvance(
text);
53 const int textWidth = fontMetrics().width(
text);
55 setMinimumWidth(textWidth + 30);
75 QStylePainter painter(
this);
76 painter.setPen(palette().color(QPalette::Text));
78 QStyleOptionComboBox opt;
82 painter.drawComplexControl(QStyle::CC_ComboBox, opt);
84 painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
90 QRect rec = QRect(geometry());
96 QRect screen = this->window()->windowHandle()->screen()->availableGeometry();
97 QPoint above = this->mapToGlobal(QPoint(0,0));
98 int aboveHeight = above.y() - screen.y();
99 QPoint below = this->mapToGlobal(QPoint(0,rec.height()));
100 int belowHeight = screen.bottom() - below.y();
103 int textWidth =
vlist_.sizeHint().width();
107 rec2.setTopLeft(below);
108 rec2.setWidth(textWidth>rec.width()? textWidth:rec.width());
109 rec2.setHeight(rec.height());
113 QCoreApplication::processEvents();
116 int contheight =
vlist_.count()*
vlist_.sizeHintForRow(0) + 4;
126 if (belowHeight==contheight || belowHeight>aboveHeight)
128 rec2.setTopLeft(below);
129 rec2.setHeight(belowHeight);
133 rec2.setTopLeft(above - QPoint(0,aboveHeight));
134 rec2.setHeight(aboveHeight);
151 QListWidgetItem* wi =
new QListWidgetItem(
text);
152 wi->setFlags(wi->flags() | Qt::ItemIsUserCheckable);
153 if (userData.toBool())
154 wi->setCheckState(Qt::Checked);
156 wi->setCheckState(Qt::Unchecked);
176 return vlist_.currentItem()->text();
188 QListWidgetItem* item =
vlist_.item(
row);
189 if (item->checkState() == Qt::Checked)
return QVariant(
true);
190 return QVariant(
false);
195 QListWidgetItem* item =
vlist_.item(
row);
196 bool wasChecked = item->checkState() == Qt::Checked;
197 if (wasChecked != checked)
199 item->setCheckState(checked?Qt::Checked:Qt::Unchecked);
208 QList<QListWidgetItem*>
list =
vlist_.selectedItems();
209 for (
int i = 0;
i <
list.count();
i++)
211 if (item->checkState() == Qt::Checked)
213 list[
i]->setCheckState(Qt::Checked);
217 list[
i]->setCheckState(Qt::Unchecked);
219 list[
i]->setSelected(
false);
228 option->initFrom(
this);