Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
spinbox-delegate.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QStyledItemDelegate>
5#include <QSpinBox>
6
9{
11
12public:
13 SpinBoxDelegate(QObject *parent = nullptr);
14
15 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
16 const QModelIndex &index) const override;
17
18 void setEditorData(QWidget *editor, const QModelIndex &index) const override;
20 const QModelIndex &index) const override;
21
22 void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
23 const QModelIndex &index) const override;
24};
26
33
36 const QStyleOptionViewItem &/* option */,
37 const QModelIndex &/* index */) const
38{
39 QSpinBox *editor = new QSpinBox(parent);
40 editor->setFrame(false);
41 editor->setMinimum(0);
42 editor->setMaximum(100);
43
44 return editor;
45}
47
50 const QModelIndex &index) const
51{
52 int value = index.model()->data(index, Qt::EditRole).toInt();
53
54 QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
56}
58
61 const QModelIndex &index) const
62{
63 QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
65 int value = spinBox->value();
66
68}
70
73 const QStyleOptionViewItem &option,
74 const QModelIndex &/* index */) const
75{
76 editor->setGeometry(option.rect);
77}
79
virtual Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
void interpretText()
This function interprets the text of the spin box.
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
The QSpinBox class provides a spin box widget.
Definition qspinbox.h:16
void setValue(int val)
Definition qspinbox.cpp:192
int value
the value of the spin box
Definition qspinbox.h:26
The QStyledItemDelegate class provides display and editing facilities for data items from a model.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
[constructor]
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
[setEditorData]
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
[setModelData]
void setEditorData(QWidget *editor, const QModelIndex &index) const override
[createEditor]
SpinBoxDelegate(QObject *parent=nullptr)
[declaration]
@ EditRole
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint index
[2]
GLuint GLenum option
#define Q_OBJECT
QSqlQueryModel * model
[16]
QSpinBox * spinBox
[0]