12 #include <QApplication> 13 #include <QCoreApplication> 14 #include <QDesktopWidget> 22 popframe_(
NULL, Qt::Popup)
28 vlist_.setSelectionMode(QAbstractItemView::MultiSelection);
29 vlist_.setSelectionBehavior(QAbstractItemView::SelectItems);
33 popframe_.layout()->setContentsMargins(0,0,0,0);
49 const int textWidth = fontMetrics().width(text);
50 setMinimumWidth(textWidth + 30);
70 QStylePainter painter(
this);
71 painter.setPen(palette().color(QPalette::Text));
73 QStyleOptionComboBox opt;
77 painter.drawComplexControl(QStyle::CC_ComboBox, opt);
79 painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
85 QRect rec = QRect(geometry());
91 QRect screen = QApplication::desktop()->screenGeometry(
this);
92 QPoint above = this->mapToGlobal(QPoint(0,0));
93 int aboveHeight = above.y() - screen.y();
94 QPoint below = this->mapToGlobal(QPoint(0,rec.height()));
95 int belowHeight = screen.bottom() - below.y();
98 int textWidth =
vlist_.sizeHint().width();
102 rec2.setTopLeft(below);
103 rec2.setWidth(textWidth>rec.width()? textWidth:rec.width());
104 rec2.setHeight(rec.height());
108 QCoreApplication::processEvents();
111 int contheight =
vlist_.count()*
vlist_.sizeHintForRow(0) + 4;
121 if (belowHeight==contheight || belowHeight>aboveHeight)
123 rec2.setTopLeft(below);
124 rec2.setHeight(belowHeight);
128 rec2.setTopLeft(above - QPoint(0,aboveHeight));
129 rec2.setHeight(aboveHeight);
146 QListWidgetItem* wi =
new QListWidgetItem(text);
147 wi->setFlags(wi->flags() | Qt::ItemIsUserCheckable);
148 if (userData.toBool())
149 wi->setCheckState(Qt::Checked);
151 wi->setCheckState(Qt::Unchecked);
171 return vlist_.currentItem()->text();
177 return vlist_.item(row)->text();
183 QListWidgetItem* item =
vlist_.item(row);
184 if (item->checkState() == Qt::Checked)
return QVariant(
true);
185 return QVariant(
false);
190 QListWidgetItem* item =
vlist_.item(row);
191 bool wasChecked = item->checkState() == Qt::Checked;
192 if (wasChecked != checked)
194 item->setCheckState(checked?Qt::Checked:Qt::Unchecked);
203 QList<QListWidgetItem*> list =
vlist_.selectedItems();
204 for (
int i = 0; i < list.count(); i++)
206 if (item->checkState() == Qt::Checked)
208 list[i]->setCheckState(Qt::Checked);
212 list[i]->setCheckState(Qt::Unchecked);
214 list[i]->setSelected(
false);
223 option->initFrom(
this);
virtual void paintEvent(QPaintEvent *e)
custom paint
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
void setItemChecked(int row, bool checked)
void itemChanged()
item changed
GLM_FUNC_DECL genType e()
GLM_FUNC_DECL genType::row_type row(genType const &m, length_t const &index)
void scanItemSelect(QListWidgetItem *item)
react on changes of the item checkbox
void addItem(const QString &text, const QVariant &userData=QVariant())
add a item to the list
QString GetDisplayText() const
get the main display text
QVariant itemData(int row)
void SetDisplayText(QString text)
the main display text
int screenbound_
lower/upper screen bound
void showPopup()
replace standard QComboBox Popup
GLM_FUNC_DECL genType abs(genType const &x)
QMultiComboBox(QWidget *widget=0)
Constructor.
void setPopupHeight(int h)
set the height of the popup
QFrame popframe_
popup frame
void setCurrentIndex(int index)
int popheight_
the height of the popup
QString m_DisplayText_
hold the main display text
ULogger class and convenient macros.
int count()
replace neccessary data access
virtual ~QMultiComboBox()
QString itemText(int row)
QListWidget vlist_
multi selection list in the popup frame
void initStyleOption(QStyleOptionComboBox *option) const
the init style