Can Qt Slot Return Value
Qt::DirectConnection 1 The slot is invoked immediately, when the signal is emitted. So I thought I could do something like i wrote above. If I well understood so the problem is that I cannot make any assumptions on if the return statement of the slot will be executed before the use of the variable in the plugin. If the signal returns a value, it is a pointer to an object of the return type of the signal, else, it is 0. If the slot returns a value, we need to copy it in arg. If it returns void, we do nothing. The problem is that it is not syntaxically correct to use the return value of a function that returns void.
The QTableView class provides a default model/view implementation of a table view. More...
Header: | #include <QTableView> |
qmake: | QT += widgets |
Inherits: | QAbstractItemView |
Inherited By: |
A dialog window is a top-level window mostly used for short-term tasks and brief communications with the user. QDialogs may be modal or modeless. QDialogs can provide a return value, and they can have default buttons. QDialogs can also have a QSizeGrip in their lower-right corner, using setSizeGripEnabled. Signals and slots are loosely coupled: A class which emits a signal neither knows nor cares which slots receive the signal. Qt's signals and slots mechanism ensures that if you connect a signal to a slot, the slot will be called with the signal's parameters at the right time. Signals and slots can take any number of arguments of any type. Def importpyqt5: ' Import PyQt5 ImportErrors raised within this function are non-recoverable ' from PyQt5 import QtGui, QtCore, QtSvg # Alias PyQt-specific functions for PySide compatibility. QtCore.Signal = QtCore.pyqtSignal QtCore.Slot = QtCore.pyqtSlot return QtCore, QtGui, QtSvg, QTAPIPYQT5.
Properties
|
|
- 16 properties inherited from QAbstractItemView
- 3 properties inherited from QAbstractScrollArea
- 6 properties inherited from QFrame
- 59 properties inherited from QWidget
- 1 property inherited from QObject
Public Functions
QTableView(QWidget *parent = nullptr) | |
virtual | ~QTableView() |
void | clearSpans() |
int | columnAt(int x) const |
int | columnSpan(int row, int column) const |
int | columnViewportPosition(int column) const |
int | columnWidth(int column) const |
Qt::PenStyle | gridStyle() const |
QHeaderView * | horizontalHeader() const |
bool | isColumnHidden(int column) const |
bool | isCornerButtonEnabled() const |
bool | isRowHidden(int row) const |
bool | isSortingEnabled() const |
int | rowAt(int y) const |
int | rowHeight(int row) const |
int | rowSpan(int row, int column) const |
int | rowViewportPosition(int row) const |
void | setColumnHidden(int column, bool hide) |
void | setColumnWidth(int column, int width) |
void | setCornerButtonEnabled(bool enable) |
void | setGridStyle(Qt::PenStyle style) |
void | setHorizontalHeader(QHeaderView *header) |
void | setRowHeight(int row, int height) |
void | setRowHidden(int row, bool hide) |
void | setSortingEnabled(bool enable) |
void | setSpan(int row, int column, int rowSpanCount, int columnSpanCount) |
void | setVerticalHeader(QHeaderView *header) |
void | setWordWrap(bool on) |
bool | showGrid() const |
void | sortByColumn(int column, Qt::SortOrder order) |
QHeaderView * | verticalHeader() const |
bool | wordWrap() const |
Reimplemented Public Functions
virtual QModelIndex | indexAt(const QPoint &pos) const override |
virtual void | setModel(QAbstractItemModel *model) override |
virtual void | setRootIndex(const QModelIndex &index) override |
virtual void | setSelectionModel(QItemSelectionModel *selectionModel) override |
- 60 public functions inherited from QAbstractItemView
- 20 public functions inherited from QAbstractScrollArea
- 14 public functions inherited from QFrame
- 214 public functions inherited from QWidget
- 31 public functions inherited from QObject
- 14 public functions inherited from QPaintDevice
Public Slots
void | hideColumn(int column) |
void | hideRow(int row) |
void | resizeColumnToContents(int column) |
void | resizeColumnsToContents() |
void | resizeRowToContents(int row) |
void | resizeRowsToContents() |
void | selectColumn(int column) |
void | selectRow(int row) |
void | setShowGrid(bool show) |
void | showColumn(int column) |
void | showRow(int row) |
- 9 public slots inherited from QAbstractItemView
- 19 public slots inherited from QWidget
- 1 public slot inherited from QObject
Static Public Members
- 5 static public members inherited from QWidget
- 9 static public members inherited from QObject
Reimplemented Protected Functions
virtual void | currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override |
virtual int | horizontalOffset() const override |
virtual bool | isIndexHidden(const QModelIndex &index) const override |
virtual QModelIndex | moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override |
virtual void | paintEvent(QPaintEvent *event) override |
virtual QModelIndexList | selectedIndexes() const override |
virtual void | selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override |
virtual void | setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) override |
virtual int | sizeHintForColumn(int column) const override |
virtual int | sizeHintForRow(int row) const override |
virtual void | timerEvent(QTimerEvent *event) override |
virtual void | updateGeometries() override |
virtual int | verticalOffset() const override |
virtual QStyleOptionViewItem | viewOptions() const override |
virtual QSize | viewportSizeHint() const override |
- 38 protected functions inherited from QAbstractItemView
- 20 protected functions inherited from QAbstractScrollArea
- 4 protected functions inherited from QFrame
- 35 protected functions inherited from QWidget
- 9 protected functions inherited from QObject
- 1 protected function inherited from QPaintDevice
Protected Slots
void | columnCountChanged(int oldCount, int newCount) |
void | columnMoved(int column, int oldIndex, int newIndex) |
void | columnResized(int column, int oldWidth, int newWidth) |
void | rowCountChanged(int oldCount, int newCount) |
void | rowMoved(int row, int oldIndex, int newIndex) |
void | rowResized(int row, int oldHeight, int newHeight) |
- 9 protected slots inherited from QAbstractItemView
- 1 protected slot inherited from QWidget
Additional Inherited Members
- 7 signals inherited from QAbstractItemView
- 3 signals inherited from QWidget
- 2 signals inherited from QObject
- 38 protected functions inherited from QAbstractItemView
- 20 protected functions inherited from QAbstractScrollArea
- 4 protected functions inherited from QFrame
- 35 protected functions inherited from QWidget
- 9 protected functions inherited from QObject
- 1 protected function inherited from QPaintDevice
Detailed Description
The QTableView class provides a default model/view implementation of a table view.
A QTableView implements a table view that displays items from a model. This class is used to provide standard tables that were previously provided by the QTable class, but using the more flexible approach provided by Qt's model/view architecture.
The QTableView class is one of the Model/View Classes and is part of Qt's model/view framework.
QTableView implements the interfaces defined by the QAbstractItemView class to allow it to display data provided by models derived from the QAbstractItemModel class.
Navigation
You can navigate the cells in the table by clicking on a cell with the mouse, or by using the arrow keys. Because QTableView enables tabKeyNavigation by default, you can also hit Tab and Backtab to move from cell to cell.
Visual Appearance
The table has a vertical header that can be obtained using the verticalHeader() function, and a horizontal header that is available through the horizontalHeader() function. The height of each row in the table can be found by using rowHeight(); similarly, the width of columns can be found using columnWidth(). Since both of these are plain widgets, you can hide either of them using their hide() functions.
Rows and columns can be hidden and shown with hideRow(), hideColumn(), showRow(), and showColumn(). They can be selected with selectRow() and selectColumn(). The table will show a grid depending on the showGrid property.
The items shown in a table view, like those in the other item views, are rendered and edited using standard delegates. However, for some tasks it is sometimes useful to be able to insert widgets in a table instead. Widgets are set for particular indexes with the setIndexWidget() function, and later retrieved with indexWidget().
By default, the cells in a table do not expand to fill the available space. You can make the cells fill the available space by stretching the last header section. Access the relevant header using horizontalHeader() or verticalHeader() and set the header's stretchLastSection property. To distribute the available space according to the space requirement of each column or row, call the view's resizeColumnsToContents() or resizeRowsToContents() functions. |
Coordinate Systems
For some specialized forms of tables it is useful to be able to convert between row and column indexes and widget coordinates. The rowAt() function provides the y-coordinate within the view of the specified row; the row index can be used to obtain a corresponding y-coordinate with rowViewportPosition(). The columnAt() and columnViewportPosition() functions provide the equivalent conversion operations between x-coordinates and column indexes.
See also QTableWidget, View Classes, QAbstractItemModel, QAbstractItemView, Chart Example, Pixelator Example, and Table Model Example.
Property Documentation
cornerButtonEnabled : bool
This property holds whether the button in the top-left corner is enabled
If this property is true
then button in the top-left corner of the table view is enabled. Clicking on this button will select all the cells in the table view.
This property is true
by default.
This property was introduced in Qt 4.3.
Access functions:
bool | isCornerButtonEnabled() const |
void | setCornerButtonEnabled(bool enable) |
gridStyle : Qt::PenStyle
This property holds the pen style used to draw the grid.
This property holds the style used when drawing the grid (see showGrid).
Access functions:
Qt::PenStyle | gridStyle() const |
void | setGridStyle(Qt::PenStyle style) |
showGrid : bool
This property holds whether the grid is shown
If this property is true
a grid is drawn for the table; if the property is false
, no grid is drawn. The default value is true.
Access functions:
bool | showGrid() const |
void | setShowGrid(bool show) |
sortingEnabled : bool
This property holds whether sorting is enabled
If this property is true
, sorting is enabled for the table. If this property is false
, sorting is not enabled. The default value is false.
Note: . Setting the property to true with setSortingEnabled() immediately triggers a call to sortByColumn() with the current sort section and order.
This property was introduced in Qt 4.2.
Access functions:
bool | isSortingEnabled() const |
void | setSortingEnabled(bool enable) |
See also sortByColumn().
wordWrap : bool
This property holds the item text word-wrapping policy
If this property is true
then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is true
by default.
Note that even of wrapping is enabled, the cell will not be expanded to fit all text. Ellipsis will be inserted according to the current textElideMode.
This property was introduced in Qt 4.3.
Access functions:
Member Function Documentation
QTableView::QTableView(QWidget *parent = nullptr)
Constructs a table view with a parent to represent the data.
See also QAbstractItemModel.
[virtual]
QTableView::~QTableView()
Destroys the table view.
void QTableView::clearSpans()
Removes all row and column spans in the table view.
This function was introduced in Qt 4.4.
See also setSpan().
int QTableView::columnAt(intx) const
Returns the column in which the given x-coordinate, x, in contents coordinates is located.
Note: This function returns -1 if the given coordinate is not valid (has no column).
See also rowAt().
[protected slot]
void QTableView::columnCountChanged(intoldCount, intnewCount)
This slot is called whenever columns are added or deleted. The previous number of columns is specified by oldCount, and the new number of columns is specified by newCount.
[protected slot]
void QTableView::columnMoved(intcolumn, intoldIndex, intnewIndex)
This slot is called to change the index of the given column in the table view. The old index is specified by oldIndex, and the new index by newIndex.
See also rowMoved().
[protected slot]
void QTableView::columnResized(intcolumn, intoldWidth, intnewWidth)
This slot is called to change the width of the given column. The old width is specified by oldWidth, and the new width by newWidth.
See also rowResized().
int QTableView::columnSpan(introw, intcolumn) const
Returns the column span of the table element at (row, column). The default is 1.
This function was introduced in Qt 4.2.
See also setSpan() and rowSpan().
int QTableView::columnViewportPosition(intcolumn) const
Returns the x-coordinate in contents coordinates of the given column.
int QTableView::columnWidth(intcolumn) const
Returns the width of the given column.
See also setColumnWidth(), resizeColumnToContents(), and rowHeight().
[override virtual protected]
void QTableView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
Reimplemented from QAbstractItemView::currentChanged().
[slot]
void QTableView::hideColumn(intcolumn)
Hide the given column.
See also showColumn() and hideRow().
[slot]
void QTableView::hideRow(introw)
Hide the given row.
See also showRow() and hideColumn().
QHeaderView *QTableView::horizontalHeader() const
Returns the table view's horizontal header.
See also setHorizontalHeader(), verticalHeader(), and QAbstractItemModel::headerData().
[override virtual protected]
int QTableView::horizontalOffset() const
Reimplemented from QAbstractItemView::horizontalOffset().
Returns the horizontal offset of the items in the table view.
Note that the table view uses the horizontal header section positions to determine the positions of columns in the view.
See also verticalOffset().
[override virtual]
QModelIndex QTableView::indexAt(const QPoint &pos) const
Reimplemented from QAbstractItemView::indexAt().
Returns the index position of the model item corresponding to the table item at position pos in contents coordinates.
bool QTableView::isColumnHidden(intcolumn) const
Returns true
if the given column is hidden; otherwise returns false
.
See also isRowHidden().
[override virtual protected]
bool QTableView::isIndexHidden(const QModelIndex &index) const
Reimplemented from QAbstractItemView::isIndexHidden().
bool QTableView::isRowHidden(introw) const
Returns true
if the given row is hidden; otherwise returns false
.
See also isColumnHidden().
[override virtual protected]
QModelIndex QTableView::moveCursor(QAbstractItemView::CursorActioncursorAction, Qt::KeyboardModifiersmodifiers)
Reimplemented from QAbstractItemView::moveCursor().
Moves the cursor in accordance with the given cursorAction, using the information provided by the modifiers.
See also QAbstractItemView::CursorAction.
[override virtual protected]
void QTableView::paintEvent(QPaintEvent *event)
Reimplemented from QAbstractScrollArea::paintEvent().
Paints the table on receipt of the given paint event event.
[slot]
void QTableView::resizeColumnToContents(intcolumn)
Resizes the given column based on the size hints of the delegate used to render each item in the column.
Note: Only visible columns will be resized. Reimplement sizeHintForColumn() to resize hidden columns as well.
See also resizeColumnsToContents(), sizeHintForColumn(), and QHeaderView::resizeContentsPrecision().
[slot]
void QTableView::resizeColumnsToContents()
Resizes all columns based on the size hints of the delegate used to render each item in the columns.
See also resizeColumnToContents(), sizeHintForColumn(), and QHeaderView::resizeContentsPrecision().
[slot]
void QTableView::resizeRowToContents(introw)
Resizes the given row based on the size hints of the delegate used to render each item in the row.
See also resizeRowsToContents(), sizeHintForRow(), and QHeaderView::resizeContentsPrecision().
[slot]
void QTableView::resizeRowsToContents()
Resizes all rows based on the size hints of the delegate used to render each item in the rows.
See also resizeRowToContents(), sizeHintForRow(), and QHeaderView::resizeContentsPrecision().
int QTableView::rowAt(inty) const
Returns the row in which the given y-coordinate, y, in contents coordinates is located.
Note: This function returns -1 if the given coordinate is not valid (has no row).
See also columnAt().
[protected slot]
void QTableView::rowCountChanged(intoldCount, intnewCount)
This slot is called whenever rows are added or deleted. The previous number of rows is specified by oldCount, and the new number of rows is specified by newCount.
int QTableView::rowHeight(introw) const
Returns the height of the given row.
See also setRowHeight(), resizeRowToContents(), and columnWidth().
[protected slot]
void QTableView::rowMoved(introw, intoldIndex, intnewIndex)
This slot is called to change the index of the given row in the table view. The old index is specified by oldIndex, and the new index by newIndex.
See also columnMoved().
[protected slot]
void QTableView::rowResized(introw, intoldHeight, intnewHeight)
This slot is called to change the height of the given row. The old height is specified by oldHeight, and the new height by newHeight.
See also columnResized().
int QTableView::rowSpan(introw, intcolumn) const
Returns the row span of the table element at (row, column). The default is 1.
This function was introduced in Qt 4.2.
See also setSpan() and columnSpan().
int QTableView::rowViewportPosition(introw) const
Returns the y-coordinate in contents coordinates of the given row.
[slot]
void QTableView::selectColumn(intcolumn)
Selects the given column in the table view if the current SelectionMode and SelectionBehavior allows columns to be selected.
See also selectRow().
[slot]
void QTableView::selectRow(introw)
Selects the given row in the table view if the current SelectionMode and SelectionBehavior allows rows to be selected.
See also selectColumn().
[override virtual protected]
QModelIndexList QTableView::selectedIndexes() const
Reimplemented from QAbstractItemView::selectedIndexes().
[override virtual protected]
void QTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Reimplemented from QAbstractItemView::selectionChanged().
void QTableView::setColumnHidden(intcolumn, boolhide)
If hide is true the given column will be hidden; otherwise it will be shown.
See also isColumnHidden() and setRowHidden().
void QTableView::setColumnWidth(intcolumn, intwidth)
Sets the width of the given column to be width.
This function was introduced in Qt 4.1.
See also columnWidth().
void QTableView::setHorizontalHeader(QHeaderView *header)
Sets the widget to use for the horizontal header to header.
See also horizontalHeader() and setVerticalHeader().
[override virtual]
void QTableView::setModel(QAbstractItemModel *model)
Reimplemented from QAbstractItemView::setModel().
[override virtual]
void QTableView::setRootIndex(const QModelIndex &index)
Reimplemented from QAbstractItemView::setRootIndex().
void QTableView::setRowHeight(introw, intheight)
Sets the height of the given row to be height.
This function was introduced in Qt 4.1.
See also rowHeight().
void QTableView::setRowHidden(introw, boolhide)
If hide is true row will be hidden, otherwise it will be shown.
See also isRowHidden() and setColumnHidden().
[override virtual protected]
void QTableView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlagsflags)
Reimplemented from QAbstractItemView::setSelection().
Selects the items within the given rect and in accordance with the specified selection flags.
[override virtual]
void QTableView::setSelectionModel(QItemSelectionModel *selectionModel)
Reimplemented from QAbstractItemView::setSelectionModel().
void QTableView::setSortingEnabled(boolenable)
If enable is true, enables sorting for the table and immediately trigger a call to sortByColumn() with the current sort section and order
Note: Setter function for property sortingEnabled.
See also isSortingEnabled().
void QTableView::setSpan(introw, intcolumn, introwSpanCount, intcolumnSpanCount)
Sets the span of the table element at (row, column) to the number of rows and columns specified by (rowSpanCount, columnSpanCount).
This function was introduced in Qt 4.2.
See also rowSpan() and columnSpan().
void QTableView::setVerticalHeader(QHeaderView *header)
Sets the widget to use for the vertical header to header.
See also verticalHeader() and setHorizontalHeader().
[slot]
void QTableView::showColumn(intcolumn)
Show the given column.
See also hideColumn() and showRow().
[slot]
void QTableView::showRow(introw)
Show the given row.
See also hideRow() and showColumn().
[override virtual protected]
int QTableView::sizeHintForColumn(intcolumn) const
Reimplemented from QAbstractItemView::sizeHintForColumn().
Returns the size hint for the given column's width or -1 if there is no model.
If you need to set the width of a given column to a fixed value, call QHeaderView::resizeSection() on the table's horizontal header.
If you reimplement this function in a subclass, note that the value you return will be used when resizeColumnToContents() or QHeaderView::resizeSections() is called. If a larger column width is required by either the horizontal header or the item delegate, the larger width will be used instead.
See also QWidget::sizeHint, horizontalHeader(), and QHeaderView::resizeContentsPrecision().
Can Qt Slot Return Value Kelley Blue Book
[override virtual protected]
int QTableView::sizeHintForRow(introw) const
Reimplemented from QAbstractItemView::sizeHintForRow().
Returns the size hint for the given row's height or -1 if there is no model.
If you need to set the height of a given row to a fixed value, call QHeaderView::resizeSection() on the table's vertical header.
If you reimplement this function in a subclass, note that the value you return is only used when resizeRowToContents() is called. In that case, if a larger row height is required by either the vertical header or the item delegate, that width will be used instead.
See also QWidget::sizeHint, verticalHeader(), and QHeaderView::resizeContentsPrecision().
void QTableView::sortByColumn(intcolumn, Qt::SortOrderorder)
Sorts the model by the values in the given column in the given order.
This function was introduced in Qt 4.2.
See also sortingEnabled.
[override virtual protected]
void QTableView::timerEvent(QTimerEvent *event)
Reimplemented from QAbstractItemView::timerEvent().
[override virtual protected]
void QTableView::updateGeometries()
Reimplemented from QAbstractItemView::updateGeometries().
QHeaderView *QTableView::verticalHeader() const
Returns the table view's vertical header.
See also setVerticalHeader(), horizontalHeader(), and QAbstractItemModel::headerData().
[override virtual protected]
int QTableView::verticalOffset() const
Reimplemented from QAbstractItemView::verticalOffset().
Returns the vertical offset of the items in the table view.
Note that the table view uses the vertical header section positions to determine the positions of rows in the view.
See also horizontalOffset().
[override virtual protected]
QStyleOptionViewItem QTableView::viewOptions() const
Reimplemented from QAbstractItemView::viewOptions().
[override virtual protected]
QSize QTableView::viewportSizeHint() const
Reimplemented from QAbstractItemView::viewportSizeHint().
© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.
This page describes the use of signals and slots in Qt for Python.The emphasis is on illustrating the use of so-called new-style signals and slots, although the traditional syntax is also given as a reference.
The main goal of this new-style is to provide a more Pythonic syntax to Python programmers.
- 2New syntax: Signal() and Slot()
Can Qt Slot Return Value Calculator
Traditional syntax: SIGNAL () and SLOT()
QtCore.SIGNAL() and QtCore.SLOT() macros allow Python to interface with Qt signal and slot delivery mechanisms.This is the old way of using signals and slots.
The example below uses the well known clicked signal from a QPushButton.The connect method has a non python-friendly syntax.It is necessary to inform the object, its signal (via macro) and a slot to be connected to.
New syntax: Signal() and Slot()
The new-style uses a different syntax to create and to connect signals and slots.The previous example could be rewritten as:
Using QtCore.Signal()
Signals can be defined using the QtCore.Signal() class.Python types and C types can be passed as parameters to it.If you need to overload it just pass the types as tuples or lists.
In addition to that, it can receive also a named argument name that defines the signal name.If nothing is passed as name then the new signal will have the same name as the variable that it is being assigned to.
The Examples section below has a collection of examples on the use of QtCore.Signal().
Note: Signals should be defined only within classes inheriting from QObject.This way the signal information is added to the class QMetaObject structure.
Using QtCore.Slot()
Slots are assigned and overloaded using the decorator QtCore.Slot().Again, to define a signature just pass the types like the QtCore.Signal() class.Unlike the Signal() class, to overload a function, you don't pass every variation as tuple or list.Instead, you have to define a new decorator for every different signature.The examples section below will make it clearer.
Another difference is about its keywords.Slot() accepts a name and a result.The result keyword defines the type that will be returned and can be a C or Python type.name behaves the same way as in Signal().If nothing is passed as name then the new slot will have the same name as the function that is being decorated.
Examples
The examples below illustrate how to define and connect signals and slots in PySide2.Both basic connections and more complex examples are given.
- Hello World example: the basic example, showing how to connect a signal to a slot without any parameters.
- Next, some arguments are added. This is a modified Hello World version. Some arguments are added to the slot and a new signal is created.
- Add some overloads. A small modification of the previous example, now with overloaded decorators.
- An example with slot overloads and more complicated signal connections and emissions (note that when passing arguments to a signal you use '[]'):
- An example of an object method emitting a signal:
- An example of a signal emitted from another QThread:
- Signals are runtime objects owned by instances, they are not class attributes: