Qt 4.8
Public Functions | Protected Functions | Private Functions | Properties | List of all members
QComboMenuDelegate Class Reference

#include <qcombobox_p.h>

Inheritance diagram for QComboMenuDelegate:
QAbstractItemDelegate QObject

Public Functions

 QComboMenuDelegate (QObject *parent, QComboBox *cmb)
 
- Public Functions inherited from QAbstractItemDelegate
virtual QWidgetcreateEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
 Returns the editor to be used for editing the data item with the given index. More...
 
virtual bool editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
 When editing of an item starts, this function is called with the event that triggered the editing, the model, the index of the item, and the option used for rendering the item. More...
 
 QAbstractItemDelegate (QObject *parent=0)
 Creates a new abstract item delegate with the given parent. More...
 
virtual void setEditorData (QWidget *editor, const QModelIndex &index) const
 Sets the contents of the given editor to the data for the item at the given index. More...
 
virtual void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
 Sets the data for the item at the given index in the model to the contents of the given editor. More...
 
virtual void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
 Updates the geometry of the editor for the item with the given index, according to the rectangle specified in the option. More...
 
virtual ~QAbstractItemDelegate ()
 Destroys the abstract item delegate. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
 This pure abstract function must be reimplemented if you want to provide custom rendering. More...
 
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const
 This pure abstract function must be reimplemented if you want to provide custom rendering. More...
 
- Protected Functions inherited from QAbstractItemDelegate
 QAbstractItemDelegate (QObjectPrivate &, QObject *parent=0)
 Creates a new abstract item delegate with the given parent. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Functions

QStyleOptionMenuItem getStyleOption (const QStyleOptionViewItem &option, const QModelIndex &index) const
 

Properties

QComboBoxmCombo
 

Additional Inherited Members

- Public Types inherited from QAbstractItemDelegate
enum  EndEditHint {
  NoHint, EditNextItem, EditPreviousItem, SubmitModelCache,
  RevertModelCache
}
 This enum describes the different hints that the delegate can give to the model and view components to make editing data in a model a comfortable experience for the user. More...
 
- Public Slots inherited from QAbstractItemDelegate
bool helpEvent (QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
 Whenever a help event occurs, this function is called with the event view option and the index that corresponds to the item where the event occurs. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QAbstractItemDelegate
void closeEditor (QWidget *editor, QAbstractItemDelegate::EndEditHint hint=NoHint)
 This signal is emitted when the user has finished editing an item using the specified editor. More...
 
void commitData (QWidget *editor)
 This signal must be emitted when the editor widget has completed editing the data, and wants to write it back into the model. More...
 
void sizeHintChanged (const QModelIndex &)
 This signal must be emitted when the sizeHint() of index changed. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QAbstractItemDelegate
static QString elidedText (const QFontMetrics &fontMetrics, int width, Qt::TextElideMode mode, const QString &text)
 Use QFontMetrics::elidedText() instead. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 265 of file qcombobox_p.h.

Constructors and Destructors

◆ QComboMenuDelegate()

QComboMenuDelegate::QComboMenuDelegate ( QObject parent,
QComboBox cmb 
)
inline

Definition at line 268 of file qcombobox_p.h.

268 : QAbstractItemDelegate(parent), mCombo(cmb) {}
QComboBox * mCombo
Definition: qcombobox_p.h:290
QAbstractItemDelegate(QObject *parent=0)
Creates a new abstract item delegate with the given parent.

Functions

◆ getStyleOption()

QStyleOptionMenuItem QComboMenuDelegate::getStyleOption ( const QStyleOptionViewItem option,
const QModelIndex index 
) const
private

Definition at line 115 of file qcombobox.cpp.

117 {
118  QStyleOptionMenuItem menuOption;
119 
120  QPalette resolvedpalette = option.palette.resolve(QApplication::palette("QMenu"));
121  QVariant value = index.data(Qt::ForegroundRole);
122  if (value.canConvert<QBrush>()) {
123  resolvedpalette.setBrush(QPalette::WindowText, qvariant_cast<QBrush>(value));
124  resolvedpalette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(value));
125  resolvedpalette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));
126  }
127  menuOption.palette = resolvedpalette;
128  menuOption.state = QStyle::State_None;
129  if (mCombo->window()->isActiveWindow())
130  menuOption.state = QStyle::State_Active;
131  if ((option.state & QStyle::State_Enabled) && (index.model()->flags(index) & Qt::ItemIsEnabled))
132  menuOption.state |= QStyle::State_Enabled;
133  else
135  if (option.state & QStyle::State_Selected)
136  menuOption.state |= QStyle::State_Selected;
138  menuOption.checked = mCombo->currentIndex() == index.row();
141  else
143 
144  QVariant variant = index.model()->data(index, Qt::DecorationRole);
145  switch (variant.type()) {
146  case QVariant::Icon:
147  menuOption.icon = qvariant_cast<QIcon>(variant);
148  break;
149  case QVariant::Color: {
150  static QPixmap pixmap(option.decorationSize);
151  pixmap.fill(qvariant_cast<QColor>(variant));
152  menuOption.icon = pixmap;
153  break; }
154  default:
155  menuOption.icon = qvariant_cast<QPixmap>(variant);
156  break;
157  }
158  if (index.data(Qt::BackgroundRole).canConvert<QBrush>()) {
160  qvariant_cast<QBrush>(index.data(Qt::BackgroundRole)));
161  }
162  menuOption.text = index.model()->data(index, Qt::DisplayRole).toString()
163  .replace(QLatin1Char('&'), QLatin1String("&&"));
164  menuOption.tabWidth = 0;
165  menuOption.maxIconWidth = option.decorationSize.width() + 4;
166  menuOption.menuRect = option.rect;
167  menuOption.rect = option.rect;
168 
169  // Make sure fonts set on the combo box also overrides the font for the popup menu.
173  || mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont()))
174  menuOption.font = mCombo->font();
175  else
176  menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font());
177 
178  menuOption.fontMetrics = QFontMetrics(menuOption.font);
179 
180  return menuOption;
181 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QRect menuRect
the rectangle for the entire menu
Definition: qstyleoption.h:449
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
QComboBox * mCombo
Definition: qcombobox_p.h:290
bool isActiveWindow
whether this widget&#39;s window is the active window
Definition: qwidget.h:186
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item...
Definition: qstyleoption.h:435
QIcon icon
the icon for the menu item
Definition: qstyleoption.h:451
QFont font
the font used for the menu item text
Definition: qstyleoption.h:454
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
int maxIconWidth
the maximum icon width for the icon in the menu item
Definition: qstyleoption.h:452
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QPalette palette()
Returns the application palette.
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
static bool isSeparator(const QModelIndex &index)
Definition: qcombobox_p.h:301
QString text
the text for the menu item
Definition: qstyleoption.h:450
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
int width() const
Returns the width.
Definition: qsize.h:126
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
int row() const
Returns the row this model index refers to.
bool checked
whether the menu item is checked or not
Definition: qstyleoption.h:447
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
FontHash * qt_app_fonts_hash()
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
int tabWidth
the tab width for the menu item
Definition: qstyleoption.h:453
QSize decorationSize
the size of the decoration for the item
Definition: qstyleoption.h:551
if(void) toggleToolbarShown
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
CheckType checkType
the type of checkmark of the menu item
Definition: qstyleoption.h:446
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int currentIndex
the index of the current item in the combobox.
Definition: qcombobox.h:71
const QFont & font() const
const char * variant
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
QPalette resolve(const QPalette &) const
Returns a new QPalette that has attributes copied from other.
Definition: qpalette.cpp:1101
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ paint()

void QComboMenuDelegate::paint ( QPainter painter,
const QStyleOptionViewItem option,
const QModelIndex index 
) const
inlineprotectedvirtual

This pure abstract function must be reimplemented if you want to provide custom rendering.

Use the painter and style option to render the item specified by the item index.

If you reimplement this you must also reimplement sizeHint().

Implements QAbstractItemDelegate.

Definition at line 271 of file qcombobox_p.h.

273  {
274  QStyleOptionMenuItem opt = getStyleOption(option, index);
275 #ifndef Q_WS_S60
276  painter->fillRect(option.rect, opt.palette.background());
277 #endif
278  mCombo->style()->drawControl(QStyle::CE_MenuItem, &opt, painter, mCombo);
279  }
QComboBox * mCombo
Definition: qcombobox_p.h:290
The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item...
Definition: qstyleoption.h:435
const QBrush & background() const
Use window() instead.
Definition: qpalette.h:134
QStyle * style() const
Definition: qwidget.cpp:2742
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
QStyleOptionMenuItem getStyleOption(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: qcombobox.cpp:115
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ sizeHint()

QSize QComboMenuDelegate::sizeHint ( const QStyleOptionViewItem option,
const QModelIndex index 
) const
inlineprotectedvirtual

This pure abstract function must be reimplemented if you want to provide custom rendering.

The options are specified by option and the model item by index.

If you reimplement this you must also reimplement paint().

Implements QAbstractItemDelegate.

Definition at line 280 of file qcombobox_p.h.

281  {
282  QStyleOptionMenuItem opt = getStyleOption(option, index);
283  return mCombo->style()->sizeFromContents(
284  QStyle::CT_MenuItem, &opt, option.rect.size(), mCombo);
285  }
QComboBox * mCombo
Definition: qcombobox_p.h:290
The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item...
Definition: qstyleoption.h:435
QStyle * style() const
Definition: qwidget.cpp:2742
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
QStyleOptionMenuItem getStyleOption(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: qcombobox.cpp:115
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90

Properties

◆ mCombo

QComboBox* QComboMenuDelegate::mCombo
private

Definition at line 290 of file qcombobox_p.h.


The documentation for this class was generated from the following files: