schrodinger.ui.qt.delegates module¶
- class schrodinger.ui.qt.delegates.CenteredIconDelegate¶
Bases:
PyQt6.QtWidgets.QStyledItemDelegate
Displays a center-aligned icon based on a
QPixmap
received fromQt.DecorationRole
. Does nothing ifQt.DecorationRole
returnsNone
.- paint(painter, option, index)¶
Paint the icon supplied by
QDecorationRole
into each cell.- Parameters
painter (QPainter) – The painter being used to render the delegate
option (QStyleOptionViewItem) – The style options to use when painting
index (QtCore.QModelIndex) – The index being represented
- class schrodinger.ui.qt.delegates.AbstractDelegateWithEditIcon(*args, **kwargs)¶
Bases:
PyQt6.QtWidgets.QStyledItemDelegate
A base class for delegates that paint an edit icon.
- Variables
EDIT_ICON (str) – The file name for the icon to paint on editable cells. This file must be in the same directory as this module.
- EDIT_ICON = ':/schrodinger/ui/qt/icons_dir/pencil_icon.ico'¶
- __init__(*args, **kwargs)¶
- class schrodinger.ui.qt.delegates.LineEditDelegate(*args, **kwargs)¶
Bases:
schrodinger.ui.qt.delegates.AbstractDelegateWithEditIcon
Delegate recommended for use with all Schrodinger table model. It’s just like the standard Qt delegate, except that if a table cell has the ItemIsEditable flag set, it will draw a “pencil” icon on the right side of the cell.
QLineEdit widget will be shown for cells that return str values for data, and QSpinBox widget will be shown for cells that return int or float values. To limit allowed min/max values, use SpinBoxDelegate.
- paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex)¶
- class schrodinger.ui.qt.delegates.MouseTrackingDelegateMixin(view)¶
Bases:
object
A mixin for a
QtWidgets.QStyledItemDelegate
that tracks which cell the mouse is in.- __init__(view)¶
- Parameters
view (QtWidgets.QTableView) – The view that this delegate will be added to. Note that mouse tracking will be enabled in the view
- property mouse_data¶
Returns the data for the cell that the mouse is in.
- Returns
the data for the cell that the mouse is on or None
- Return type
object
- createEditor(parent, option, index)¶
This delegate does not have a separate editor widget, so we return None. All arguments are ignored, but are present for Qt compatibility.
- eventFilter(viewport, event)¶
The delegate does not receive Leave events or MouseMove events that don’t occur over an index (e.g. events that occur over a header or over blank space in the view), so we have to act as an event filter for the view’s viewport to observe these events.
- Parameters
viewport (QtWidgets.QWidget) – The view’s viewport. Not used, but present for compatibility with Qt’s event filtering.
event (QtCore.QEvent) – The event to filter
- Returns
True if the event was handled and does not need to be passed to the viewport. False otherwise. We want all events to be passed to the viewport, so we always return False.
- Return type
bool
- class schrodinger.ui.qt.delegates.PushButtonDelegate(view, role=None)¶
Bases:
schrodinger.ui.qt.delegates.MouseTrackingDelegateMixin
,PyQt6.QtWidgets.QStyledItemDelegate
A delegate containing a clickable push button. The button name will be taken from the Qt.DisplayRole data. Then clicked, this delegate will emit a
clicked
signal with either:If
role
is None, aQtCore.QModelIndex
for the cell that was clicked.Otherwise, the
role
data for the cell that was clicked.
- clicked¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- __init__(view, role=None)¶
- Parameters
view (
QtWidgets.QTableView
) – The view that this delegate will be added to. Note that mouse tracking will be enabled in the view.role (int or NoneType) – The role to emit data for when a button is clicked. If not given, the index that was clicked will be emitted instead. This value may be specified after instantiation using
setRole
.
- setRole(role)¶
Specify the role to emit data for when a button is clicked. If None, the index that was clicked will be emitted instead.
- Parameters
role (int or NoneType) – The role
- paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex)¶
- editorEvent(event, model, option, index)¶
Handle mouse clicks and key presses. Left clicking on the button or hitting the space bar will emit the clicked signal. Left clicks outside of the button will be handled as normal (i.e. selecting the cell).
See Qt documentation for documentation on arguments and return value.
- eventFilter(viewport, event)¶
The delegate does not receive Leave events or MouseMove events that don’t occur over an index (e.g. events that occur over a header or over blank space in the view), so we have to act as an event filter for the view’s viewport to observe these events. Without these events, we may not know when the mouse is no longer over a button, so we won’t know when to remove mouse-over highlighting on the button. Since this class has tokeep track of
_btn_down
and_mouse_over
the parent class’ eventFilter can not be used.- Parameters
viewport (
QtWidgets.QWidget
) – The view’s viewport. Not used, but present for compatibility with Qt’s event filtering.event (
QtCore.QEvent
) – The event to filter
- Returns
True if the event was handled and does not need to be passed to the viewport. False otherwise. We want all events to be passed to the viewport, so we always return False.
- Return type
bool
- sizeHint(self, option: QStyleOptionViewItem, index: QModelIndex) QSize ¶
- sizeHintForText(txt)¶
Generate a size hint using the specified text.
- Parameters
txt (str) – The text to use for determining the button’s size
- Returns
The calculated size hint
- Return type
QtCore.QSize
- class schrodinger.ui.qt.delegates.SpinBoxDelegate(*args, **kwargs)¶
Bases:
schrodinger.ui.qt.delegates.LineEditDelegate
A delegate that provides a
QtWidgets.QSpinBox
as an editor. The minimum and maximum allowed values for the spin box are set using data retrieved via the SPINBOX_LIMITS_ROLE.Editing is initiated when the cell is clicked. Note that the mouse down and up must both occur in the same cell; otherwise, editing will not be started. This allows the user to highlight multiple cells by clicking and dragging.
NOTE: Use STableView in order to enter the edit mode after a click.
- SPINBOX_LIMITS_ROLE = 357¶
- MOUSE_CLICK_STARTS_EDIT = True¶
- createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex) QWidget ¶
- setEditorData(self, editor: QWidget, index: QModelIndex)¶
- setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex)¶
- updateEditorGeometry(self, editor: QWidget, option: QStyleOptionViewItem, index: QModelIndex)¶
- class schrodinger.ui.qt.delegates.ComboBoxDelegate(*args, **kwargs)¶
Bases:
schrodinger.ui.qt.delegates.AbstractDelegateWithEditIcon
A delegate that provides a
_TableComboBox
as an editor. The combo box is populated using a list or OrderedDict retrieved via the COMBOBOX_ROLE.NOTE: Use STableView in order to open the combo menu with a single click.
- COMBOBOX_ROLE = 358¶
- MOUSE_PRESS_STARTS_EDIT = True¶
- EDIT_ICON = ':/schrodinger/ui/qt/icons_dir/combobox_icon.ico'¶
- paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex)¶
- createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex) QWidget ¶
- setEditorData(self, editor: QWidget, index: QModelIndex)¶
- setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex)¶
- class schrodinger.ui.qt.delegates.MatplotlibDelegate(parent=None)¶
Bases:
PyQt6.QtWidgets.QStyledItemDelegate
A delegate that displays a matplotlib plot for all data of type PLOT_DATA_TYPE. Data of other types will be displayed normally (i.e. as a string). A small plot (generated in
_genCellPlot
) will be shown inside of the cell and a larger plot (generated in_genToolTipPlot
) will be shown in a tool-tip-style pop up if the user hovers over a cell. Data for the small plot is retrieved using Qt.UserRole. Data for the tool tip plot is retrieved using Qt.ToolTipRole.This class should not be instantiated directly and must be subclassed. Subclasses must redefine
_genCellPlot
and may also redefine_genToolTipPlot
and the class variables.- Variables
TOOLTIP_PLOT (bool) – Whether the matplotlib tool tip pop up should be used. If this is False, all of the other TOOLTIP_PLOT_* constants will be ignored, as will
_genToolTipPlot
.TOOLTIP_PLOT_WIDTH (int) – The width of the plots shown in the tool tip popup
TOOLTIP_PLOT_HEIGHT (int) – The height of the plots shown in the tool tip popup
TOOLTIP_FRAME_WIDTH (int) – The thickness of the border around the tool tip plot popup
PLOT_DATA_TYPE (type or tuple) – Data of this type (or tuple of types) will result in a matplotlib plot. Other data types will result in standard table behavior.
- TOOLTIP_PLOT = True¶
- TOOLTIP_PLOT_WIDTH = 640¶
- TOOLTIP_PLOT_HEIGHT = 480¶
- TOOLTIP_FRAME_WIDTH = 1¶
- PLOT_DATA_TYPE = (<class 'list'>, <class 'tuple'>)¶
- __init__(parent=None)¶
- createEditor(parent, option, index)¶
This delegate does not have a separate editor widget, so we return None. All arguments are ignored, but are present for Qt compatibility.
- paint(painter, option, index)¶
Paint the cell contents
- Parameters
painter (QPainter) – The painter being used to render the delegate
option (QStyleOptionViewItem) – The style options to use when painting
index (
PyQt5.QtCore.QModelIndex
) – The index being represented
- helpEvent(event, view, option, index)¶
Handle help events. If the index has data of type self.PLOT_DATA_TYPE for Qt.ToolTipRole, a pop up plot will be generated. All other events will be handled as usual. Before generating a pop up, make sure that a pop up for the given index isn’t already displayed. If it is, don’t do anything.
- Parameters
event (
QtGui.QHelpEvent
) – The event to be handledview (
QtWidgets.QTableView
) – The view that this delegate is used inoption – Ignored, but present for Qt compatibility.
index (
QtCore.QModelIndex
) – The index of the cell where the event occurred
- Returns
True if the event was handled. False otherwise.
- Return type
bool
- class schrodinger.ui.qt.delegates.ModelIndexFilter(data, index)¶
Bases:
PyQt6.QtCore.QModelIndex
An index that can override the data provided by a model.
- Note
Qt’s QModelIndex functions are all inlined. As a result, any functions implemented in a QModelIndex subclass are bypassed when called from C++. Because of this, we have to implement this class using a real index to a dummy model (
_DummyModel
) rather than using a dummy index with its own data() method.
- class schrodinger.ui.qt.delegates.DefaultMessageDelegate(parent=None, message='Double-click to edit...')¶
Bases:
PyQt6.QtWidgets.QStyledItemDelegate
A delegate that displays a default “Double-click to edit” message when there is no data to display. This way, the model and the editor don’t have to treat no-data as a special case. Note that the model background color will still be used.
- FONT = <PyQt6.QtGui.QFont object>¶
- FOREGROUND = <PyQt6.QtGui.QBrush object>¶
- __init__(parent=None, message='Double-click to edit...')¶
- paint(painter, option, index)¶
If the DisplayRole data for index is empty, paint the default message instead.
See Qt documentation for an explanation of arguments.
- class schrodinger.ui.qt.delegates.AbstractCustomDelegate¶
Bases:
PyQt6.QtWidgets.QStyledItemDelegate
- paintItemBackground(painter, option, index)¶
Paints the item’s background.
- Parameters
painter (
QtGui.QPainter
) – The painter to useoption (
QtWidgets.QStyleOptionViewItem
) – The options for the cellindex (
QtCore.QModelIndex
) – The index to paint
- Returns
Instance of
QtWidgets.QStyleOptionViewItem
initialized using original option and an instance ofQStyle
- Return type
tuple of
QtWidgets.QStyleOptionViewItem
,QStyle
- class schrodinger.ui.qt.delegates.WorkspaceInclusionDelegate(parent)¶
Bases:
schrodinger.ui.qt.delegates.AbstractCustomDelegate
A delegate for representing workspace inclusion as it is shown in the project table. This delegate allows an entry to be set as the only workspace entry by clicking, or allows workspace inclusion to be toggled by holding down Ctrl.
NOTE: If using schrodinger.ui.qt.delegates.WorkspaceInclusionDelegate, this delegate expects the model to provide the number of included entries for NUM_INCLUDED_ENTRIES_ROLE. If this data is not provided, a black inclusion icon will be used for any number of inclusions, including 1.
- __init__(parent)¶
- createEditor(parent, option, index)¶
This delegate does not have a separate editor widget, so we return None. All arguments are ignored, but are present for Qt compatibility.
- paint(painter, option, index)¶
Paint the appropriate icon
- Parameters
painter (QPainter) – The painter being used to render the delegate
option (QStyleOptionViewItem) – The style options to use when painting
index (
PyQt5.QtCore.QModelIndex
) – The index being represented
- editorEvent(event, model, option, index)¶
Handle mouse clicks and key presses
- Parameters
event (
PyQt5.QtCore.QEvent
) – The event that occurredmodel (QAbstractTableModel) – The data model
option – Ignored, but present for Qt compatibility
index (
PyQt5.QtCore.QModelIndex
) – The index being edited
- Returns
True if the event was handled. False otherwise.
- Return type
bool
- class schrodinger.ui.qt.delegates.PictureDelegate(parent=None, padding_factor=0.04, alignment=None)¶
Bases:
schrodinger.ui.qt.delegates.AbstractCustomDelegate
An abstract delegate class that can render images along with text.
This delegate queries the table’s
Qt.DisplayRole
for data that informs how it should render an image. This data must be an instance ofDISPLAY_DATA_CLASS
. If not, this delegate will revert to default delegate behavior.This delegate also queries the custom
PICTURE_TEXT_ROLE
role for text to display along with the generated image. The text color can be set if the table returns the appropriateQtGui.QBrush
whenQt.ForegroundRole
is queried.Images should be cached for faster rendering after the first render. They are stored in a cache that can be cleared via the
clearImageCache
method when the model’s data changes, if necessary.- Subclasses should define the following:
- -DISPLAY_DATA_CLASS: class variable that indicates the expected type of
the display data to be received from the table.
- -_getPicture(): method that actually generates the picture to be
rendered. Should only be accessed via the
getPicture()
method
- Variables
padding_factor – The portion of a cell’s width and height to be used as padding on each side of the cell when drawing the image. Default value 0.04.
- TEXT_MARGIN = 2¶
- DISPLAY_DATA_CLASS = None¶
- __init__(parent=None, padding_factor=0.04, alignment=None)¶
Initialize a new delegate instance, optionally specifying the size of the padding in the cell around the image.
- Parameters
padding_factor (
float
) – The portion of the cell’s width and height to be used as padding on each side of the cell when drawing the image.alignment (
QtCore.QAlignment
) – The alignment of the text, if any text is provided by the cell data method. Vertical alignment specifies whether the text is displayed above or below the structure image.
- setAlignment(alignment)¶
Set the text alignment for the cell. The vertical component of the alignment indicates whether the text will be displayed above or below the structure image.
The vertical component of the alignment must either be
Qt.AlignTop
orQt.AlignBottom
; if it is neither of these, the vertical alignment will default toQt.AlignTop
.If this delegate is not provided with both a structure and text to display, this alignment setting is ignored.
- Parameters
alignment (
QtCore.Alignment
) – Text alignment in table cell.- Raises
ValueError – if the vertical component of the alignment is specified to be Qt.AlignVCenter
- alignment()¶
- setTextElide(elide)¶
Set the text elide status of the text displayed by the delegate. The elide mode describes where the ellipsis should appear when displaying text that doesn’t fit into the available space.
- Parameters
elide (
Qt.TextElideMode
) – text elide mode
- textElide()¶
- setPaddingFactor(padding_factor)¶
Set the relative size of the cell width and height used as padding for the image.
If the table view has already been painted,
view.update
should be called aftersetPaddingFactor
to make sure that the visible cells are properly updated.- Raises
TypeError – when the supplied
padding_factor
is not a floatValueError – when the supplied
padding_factor
is less than 0.0 or greater than 0.5.
- Parameters
padding_factor (
float
) – The portion of the cell’s width and height to be used as padding on each side of the cell when drawing the image.
- paddingFactor()¶
- paint(painter, option, index)¶
Arrange and paint image, and optionally text, into the table cell.
See
QtWidgets.QAbstractItemDelegate.paint
for argument documentation.
- paintText(painter, option, index, rect)¶
Paint supplied text into a subsection of the supplied rectangle.
- Parameters
painter (
QtGui.QPainter
) – The painter that is drawing in the tableoption (
QtGui.QStyleOptionViewItem
) – Class containing parameters used to draw the cellindex (
QtCore.QModelIndex
) – Index for the cell to be paintedrect (
QtCore.QRect
) – The rectangle in which the text should be painted
- Returns
If text is drawn, a rectangle contained entirely within the larger painting area that contains the painted text, or
None
if no text was provided.- Return type
QtCore.QRect
orNone
- paintPicture(display_data, painter, rect)¶
Paint the picture into the supplied rectangle.
- Parameters
display_data (
DISPLAY_DATA_CLASS
) – object used to generate the imagepainter (
QtGui.QPainter
) – The painter that is drawing in the tablerect (
QtCore.QRect
) – The rectangle in which the image should be painted
- getPicture(*args, **kwargs) PyQt6.QtGui.QPicture ¶
Outward-facing API for accessing a picture.
This method should not be overridden in subclasses; instead,
_getCacheableArgs()
and_getPicture()
should be.
- getContentRect(rect)¶
Given the rectangle representing the total area in the table cell, return a (potentially) smaller rectangle that remains after the portion of the rectangle dedicated to padding is removed.
- Parameters
rect (
QtCore.QRect
) – the rectangle corresponding to the full table cell area- Returns
the rectangle corresponding to the subset of the table area devoted to the cell contents (full cell minus padding area, if any)
- Return type
QtCore.QRect
- clearImageCache()¶
Clear the image cache. This function can be called from a subclass if the
functools.lru_cache
decorator is applied togetPicture
.
- class schrodinger.ui.qt.delegates.HashableRdMol(rdmol: rdkit.Chem.rdchem.Mol, atom_idcs: Optional[Tuple[int, ...]] = None, color: Optional[Tuple[int, int, int]] = None, atom_labels: Optional[List[str]] = None, width_height: Optional[Tuple[int, int]] = None)¶
Bases:
object
A
rdchem.Mol
wrapper that extracts data from therdchem.Mol
object and uses it to form a useful hash value. This is necessary to ensure that ardchem.Mol
instance is not accidentally matched with a totally differentrdchem.Mol
because they happen to share the same memory location (at different times).Since this type of object is intended for use with the
RdMolDelegate
, the options used for rendering this as a picture are included in the hash.- __init__(rdmol: rdkit.Chem.rdchem.Mol, atom_idcs: Optional[Tuple[int, ...]] = None, color: Optional[Tuple[int, int, int]] = None, atom_labels: Optional[List[str]] = None, width_height: Optional[Tuple[int, int]] = None)¶
- Note
as of this writing, sketcher does not appear to support rendering both custom atom coloring and atom labels.
- Parameters
rdmol – the molecule for which the 2D image will be rendered
atom_idcs – optionally, atom indices for
rdmol
which should be colored. Will be ignored ifcolor
is not specified.color – a (red, green, blue) tuple describing the color of the atoms (optionally) specified by
atom_idcs
. Will be ignored ifatom_idcs
is not specified.atom_labels – optionally, text labels to annotate each atom. The labeled atom is specified by the index of the label within the list, so we must have
len(atom_labels) == rdmol.GetNumAtoms()
width_height – optionally, the width and height of the 2D image
- class schrodinger.ui.qt.delegates.RdMolDelegate(parent=None, padding_factor=0.04, alignment=None)¶
Bases:
schrodinger.ui.qt.delegates.PictureDelegate
Delegate that uses RDKit and sketcher to display a 2D image of a small molecule.
Input
Mol
objects can use implicit or explicit hydrogens.- DISPLAY_DATA_CLASS¶
alias of
rdkit.Chem.rdchem.Mol
- paintPicture(display_data, painter, rect)¶
Paint the picture into the supplied rectangle.
- Parameters
display_data (
DISPLAY_DATA_CLASS
) – object used to generate the imagepainter (
QtGui.QPainter
) – The painter that is drawing in the tablerect (
QtCore.QRect
) – The rectangle in which the image should be painted
- class schrodinger.ui.qt.delegates.StructureDelegate(parent=None, padding_factor=0.04, alignment=None)¶
Bases:
schrodinger.ui.qt.delegates.RdMolDelegate
Delegate used to display a 2D image of a small molecule.
- DISPLAY_DATA_CLASS¶
- class schrodinger.ui.qt.delegates.CheckboxDelegate¶
Bases:
schrodinger.ui.qt.delegates.AbstractCustomDelegate
This delegate contains a clickable checkbox. The checkbox is only displayed if the index contains data for the Qt.CheckStateRole role. If the Qt.CheckStateRole role is None, then the standard delegate behavior will be used. The index must flagged as enabled and editable for clicks to toggle the model value, and clicks must occur on the checkbox itself. Clicks on other areas of the cell will be handled as normal (i.e. selecting the cell). Model.setData() will be called with the default role (i.e. Qt.EditRole) when toggling the checkbox value. Note that this delegate uses a bi-state rather than tri-state checkbox, so partially checked states are not allowed.
- DRAW_STYLE = 3¶
- createEditor(parent, option, index)¶
This delegate does not have a separate editor widget, so we return None. All arguments are ignored, but are present for Qt compatibility.
- paint(painter, option, index)¶
Paint the appropriate icon
- Parameters
painter (
PyQt5.QtGui.QPainter
) – The painter being used to render the delegateoption (
PyQt5.QtWidgets.QStyleOptionViewItem
) – The style options to use when paintingindex (
PyQt5.QtCore.QModelIndex
) – The index being represented
- editorEvent(event, model, option, index)¶
Handle mouse clicks and key presses. Left clicking on the check box or hitting the space bar will toggle the check box value. Left clicks outside of the checkbox will be handled as normal (i.e. selecting the cell).
- Parameters
event (
PyQt5.QtCore.QEvent
) – The event that occurredmodel (QAbstractTableModel) – The data model
option (QStyleOptionViewItem) – The style options for the cell
index (
PyQt5.QtCore.QModelIndex
) – The index being edited
- Returns
True if the event was handled. False otherwise.
- Return type
bool
- sizeHint(option=None, index=None)¶
Provide a reasonable default size for the table cell. If no index is provided, then option is not required and it is assumed that the cell contains check data.
See Qt documentation for an explanation of arguments and return type
- class schrodinger.ui.qt.delegates.RadioButtonDelegate¶
Bases:
schrodinger.ui.qt.delegates.CheckboxDelegate
Subclass of
CheckboxDelegate
giving the widget a radio button appearance. Note that the model must define check state behavior, e.g. to uncheck all other rows when a new row is checked.- DRAW_STYLE = 5¶
- paint(painter, option, index)¶
Paint the appropriate icon
- Parameters
painter (
PyQt5.QtGui.QPainter
) – The painter being used to render the delegateoption (
PyQt5.QtWidgets.QStyleOptionViewItem
) – The style options to use when paintingindex (
PyQt5.QtCore.QModelIndex
) – The index being represented
- class schrodinger.ui.qt.delegates.ProgressBarDelegate¶
Bases:
schrodinger.ui.qt.delegates.AbstractCustomDelegate
This delegate displays if the Qt.DisplayRows datat is an int or tuple; standard delegate behavior is invoked otherwise.
Integer values are displayed as percentages on the progress bar. These must be between -100 and 100.
The tuple should consist of (value, maximum), in which case the progress text is shown as abs(value)/maximum.
A negative value flags the existence of an error and changes the color to orange.
- DRAW_STYLE = 10¶
- createEditor(parent, option, index)¶
This delegate does not have a separate editor widget, so we return None. All arguments are ignored, but are present for Qt compatibility.
- paint(painter, option, index)¶
Paint the progress bar or use the default delegate
- Parameters
painter (
QtGui.QPainter
) – The painter being used to render the delegateoption (
QtWidgets.QStyleOptionViewItem
) – The style options to use when paintingindex (
QtCore.QModelIndex
) – The index being represented
- sizeHint(option=None, index=None)¶
Provide a reasonable default size for the table cell. If no index is provided, then option is not required and it is assumed that the cell contains progress bar data.
See Qt documentation for an explanation of arguments and return type
- class schrodinger.ui.qt.delegates.ToolTipIconDelegate(parent, icon)¶
Bases:
schrodinger.ui.qt.delegates.AbstractCustomDelegate
A delegate for drawing an icon which shows a tooltip when clicked when user hovers the mouse over the cell. Tool tip text must be returned by the model’s data() method for the ToolTipRole.
- __init__(parent, icon)¶
Initialize the delegate. :param parent: Parent view widget :param icon: QIcon to draw in the cell.
- paint(painter, option, index)¶
Paint the appropriate icon, but only for cells that have a ToolTipRole.
- Parameters
painter (QPainter) – The painter being used to render the delegate
option (QStyleOptionViewItem) – The style options to use when painting
index (
PyQt5.QtCore.QModelIndex
) – The index being represented
- editorEvent(event, model, option, index)¶
Handle mouse clicks: show tool tip if the cell is clicked.
- class schrodinger.ui.qt.delegates.LinkDelegate(view, role=None, link_role=None)¶
Bases:
schrodinger.ui.qt.delegates.PushButtonDelegate
A delegate containing a clickable text. Text will be taken from the Qt.DisplayRole data. When clicked, this delegate will emit a
clicked
signal with either:If
role
is None, aQtCore.QModelIndex
for the cell that was clicked.Otherwise, the
role
data for the cell that was clicked.
When optional link role is provided data with that is checked to determine whether link should be enabled. When link role is None link is always enabled. When link is disabled clicked signal is not emitted.
- Variables
DISABLED_STYLE (str) – style sheet that sets button text to standard disabled link color
ENABLED_STYLE (str) – style sheet that sets button text to “Maestro blue” to match standard link appearance
_cursor_over_delegate (bool) – whether the cursor is over the delgate
_cursor_override_active (bool) – whether the “pointing hand” cursor override is currently in effect
- DISABLED_STYLE = 'QPushButton {color: #acb8bf}'¶
- ENABLED_STYLE = 'QPushButton {color: #2e9cdc}'¶
- __init__(view, role=None, link_role=None)¶
- Parameters
view (QtWidgets.QTableView) – The view that this delegate will be added to. Note that mouse tracking will be enabled in the view.
role (int or NoneType) – The role to emit data for when a button is clicked. If not given, the index that was clicked will be emitted instead. This value may be specified after instantiation using
setRole
.link_role (int or NoneType) – The role to check data that determines whether link should be enabled. (Note: may need to use a role different from Qt.DisplayRole if the link should use the disabled stylesheet)
- indexIsEnabled(index)¶
- Returns
whether the specified index should have an enabled link
- Return type
bool
- paint(painter, option, index)¶
Temporarily updates the painter font to be bold to match standard link appearance.
- eventFilter(viewport, event)¶
Catch all events in order to apply the correct appearance to the cursor based on its position.
- Parameters
viewport (QtWidgets.QWidget) – The view’s viewport. Not used, but present for compatibility with Qt’s event filtering.
event (QtCore.QEvent) – The event to filter
- Returns
True if the event was handled and does not need to be passed to the viewport. False otherwise. We want all events to be passed to the viewport, so we always return False.
- Return type
bool
- schrodinger.ui.qt.delegates.structure_tuple(st)¶
Produce a hashable
tuple
to identify a structure by its Cartesian coordinates and atom types.- Parameters
st (
structure.Structure
) – a structure instance- Returns
two tuples containing a subset of the data from the structure instance. The first contains the atom types; The second contains the Cartesian coordinates of the atoms.
- Return type
tuple(tuple(str), tuple(float))