[PyQt] modifying a Qt Class: how to get the equivalent of macro Q_D
in PyQt?
TP
paratribulations at free.fr
Thu Jun 25 16:03:47 BST 2009
Hi everybody,
I have subclassed QComboBox. For example I have changed paintEvent to get a
customized look. It works perfectly. But I have also to change the behavior
of the mouse wheel on the combo box. For this, I would like to subclass the
function wheelEvent of QComboBox (see below its C++ source code, you can
find it in the Qt source code in the directory
src/gui/widgets/qcombobox.cpp).
This function seems easy to understand and subclass, except for one thing:
the macro Q_D creates a pointer d. How to do the same thing in PyQt? What
is the PyQt equivalent of Q_D?
Thanks a lot,
Julien
###### method wheelEvent of QComboBox
void QComboBox::wheelEvent(QWheelEvent *e)
{
Q_D(QComboBox);
if (!d->viewContainer()->isVisible()) {
int newIndex = currentIndex();
if (e->delta() > 0) {
newIndex--;
while ((newIndex >= 0) &&
(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) &
Qt::ItemIsEnabled))
newIndex--;
} else {
newIndex++;
while ((newIndex < count()) &&
(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) &
Qt::ItemIsEnabled))
newIndex++;
}
if (newIndex >= 0 && newIndex < count() && newIndex !=
currentIndex()) {
setCurrentIndex(newIndex);
d->emitActivated(d->currentIndex);
}
e->accept();
}
}
--
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"
"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)
More information about the PyQt
mailing list