이 페이지에서

QItemSelectionModel Class

QItemSelectionModel 클래스는 뷰에서 선택된 항목을 관리합니다. 더 보기...

헤더: #include <QItemSelectionModel>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
상속: QObject

공개 유형

enum SelectionFlag { NoUpdate, Clear, Select, Deselect, Toggle, …, ClearAndSelect }
flags SelectionFlags

속성

공개 함수

QItemSelectionModel(QAbstractItemModel *model = nullptr)
QItemSelectionModel(QAbstractItemModel *model, QObject *parent)
virtual ~QItemSelectionModel()
bool columnIntersectsSelection(int column, const QModelIndex &parent = QModelIndex()) const
QModelIndex currentIndex() const
bool hasSelection() const
bool isColumnSelected(int column, const QModelIndex &parent = QModelIndex()) const
bool isRowSelected(int row, const QModelIndex &parent = QModelIndex()) const
bool isSelected(const QModelIndex &index) const
QAbstractItemModel *model()
const QAbstractItemModel *model() const
bool rowIntersectsSelection(int row, const QModelIndex &parent = QModelIndex()) const
QModelIndexList selectedColumns(int row = 0) const
QModelIndexList selectedIndexes() const
QModelIndexList selectedRows(int column = 0) const
const QItemSelection selection() const
void setModel(QAbstractItemModel *model)

공개 슬롯

virtual void clear()
virtual void clearCurrentIndex()
void clearSelection()
virtual void reset()
virtual void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)

신호

void currentChanged(const QModelIndex &current, const QModelIndex &previous)
void currentColumnChanged(const QModelIndex &current, const QModelIndex &previous)
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
void modelChanged(QAbstractItemModel *model)
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)

보호된 함수

void emitSelectionChanged(const QItemSelection &newSelection, const QItemSelection &oldSelection)

상세 설명

QItemSelectionModel은 뷰 또는 동일한 모델을 참조하는 여러 뷰에서 선택된 항목을 추적합니다. 또한 뷰에서 현재 선택된 항목도 추적합니다.

QItemSelectionModel 클래스는 모델/뷰 클래스 중 하나이며, Qt의 모델/뷰 프레임워크의 일부입니다.

선택된 항목은 범위를 사용하여 저장됩니다. 선택된 항목을 수정하려면 select()를 사용하고, QItemSelection 또는 QModelIndex 와 QItemSelectionModel::SelectionFlag 중 하나를 지정하십시오.

QItemSelectionModel은 선택 관리에 두 단계 접근 방식을 취하며, 확정된 선택 항목과 현재 선택 범위에 포함된 항목을 모두 처리합니다. 현재 선택된 항목들은 현재 상호작용 선택(예: 고무줄 선택 또는 키보드 Shift 키를 이용한 선택)의 일부입니다.

현재 선택된 항목을 업데이트하려면 QItemSelectionModel::Current 과 다른 SelectionFlags 중 하나와 비트별 OR 연산을 사용하십시오. QItemSelectionModel::Current 명령을 생략하면 새로운 현재 선택 영역이 생성되고, 이전 선택 영역은 전체 선택 영역에 추가됩니다. 모든 함수는 두 계층 모두에서 작동합니다. 예를 들어, selecteditems()는 두 계층의 항목을 모두 반환합니다.

참고: 5.5버전부터 model, hasSelection 및 currentIndex 는 메타 객체 속성입니다.

‘모델/뷰 프로그래밍 ’ 및 ‘ QAbstractItemModel ’항목도 참조하십시오 .

멤버 유형 문서

enum QItemSelectionModel::SelectionFlag
flags QItemSelectionModel::SelectionFlags

이 열거형은 선택 모델이 업데이트되는 방식을 설명합니다.

상수값설명
QItemSelectionModel::NoUpdate0x0000선택이 이루어지지 않습니다.
QItemSelectionModel::Clear0x0001선택 내용이 모두 지워집니다.
QItemSelectionModel::Select0x0002지정된 모든 인덱스가 선택됩니다.
QItemSelectionModel::Deselect0x0004지정된 모든 인덱스의 선택이 해제됩니다.
QItemSelectionModel::Toggle0x0008지정된 모든 인덱스는 현재 상태에 따라 선택되거나 선택 해제됩니다.
QItemSelectionModel::Current0x0010현재 선택 사항이 업데이트됩니다.
QItemSelectionModel::Rows0x0020모든 인덱스가 행을 포괄하도록 확장됩니다.
QItemSelectionModel::Columns0x0040모든 인덱스가 열을 포괄하도록 확장됩니다.
QItemSelectionModel::SelectCurrentSelect | Current편의를 위해 '선택'과 '현재'의 조합이 제공됩니다.
QItemSelectionModel::ToggleCurrentToggle | Current편의를 위해 '토글'과 '현재'의 조합이 제공됩니다.
QItemSelectionModel::ClearAndSelectClear | Select편의를 위해 Clear와 Select의 조합이 제공됩니다.

SelectionFlags 유형은 QFlags<SelectionFlag>에 대한 typedef입니다. 이 유형은 SelectionFlag 값들의 OR 조합을 저장합니다.

속성 설명

[read-only] selectedIndexes : QModelIndexList

액세스 기능:

QModelIndexList selectedIndexes() const

알림 신호:

void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)

멤버 함수 문서

[explicit] QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model = nullptr)

지정된 항목 model 을 대상으로 작동하는 선택 모델을 생성합니다.

[explicit] QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model, QObject *parent)

지정된 항목 model 에 대해 parent 를 적용하는 선택 모델을 생성합니다.

[virtual noexcept] QItemSelectionModel::~QItemSelectionModel()

선택 모델을 삭제합니다.

[virtual slot] void QItemSelectionModel::clear()

선택 모델을 지웁니다. ` selectionChanged()` 및 ` currentChanged()` 이벤트를 발생시킵니다.

[virtual slot] void QItemSelectionModel::clearCurrentIndex()

현재 인덱스를 지웁니다. ` currentChanged()`를 발생시킵니다.

[slot] void QItemSelectionModel::clearSelection()

선택 모델에서 선택 항목을 지웁니다. ` selectionChanged()` 이벤트를 발생시킵니다.

[invokable] bool QItemSelectionModel::columnIntersectsSelection(int column, const QModelIndex &parent = QModelIndex()) const

column 에서 지정된 parent 을 가진 항목이 선택된 경우, true 을 반환합니다.

참고: Qt 5.15부터 parent 의 기본 인수는 빈 모델 인덱스입니다.

참고: 이 함수는 메타 객체 시스템과 QML을 통해 호출할 수 있습니다. Q_INVOKABLE 을 참조하십시오.

[signal] void QItemSelectionModel::currentChanged(const QModelIndex &current, const QModelIndex &previous)

이 신호는 현재 항목이 변경될 때마다 발생합니다. 선택 항목의 현재 항목으로 previous 모델 항목 인덱스가 current 인덱스로 대체됩니다.

항목 모델이 재설정될 때는 이 신호가 발생하지 않는다는 점에 유의하십시오.

currentIndex(), setCurrentIndex(), selectionChanged()도 참조하십시오 .

[signal] void QItemSelectionModel::currentColumnChanged(const QModelIndex &current, const QModelIndex &previous)

current 항목이 변경되고 해당 열이 previous 의 현재 항목 열과 다를 경우 이 신호가 발생합니다.

단, 항목 모델이 재설정될 때는 이 신호가 발생하지 않습니다.

currentChanged(), currentRowChanged(), currentIndex(), setCurrentIndex()도 참조하십시오 .

QModelIndex QItemSelectionModel::currentIndex() const

현재 항목에 대한 모델 항목 인덱스를 반환하거나, 현재 항목이 없는 경우 유효하지 않은 인덱스를 반환합니다.

setCurrentIndex()도 참조하십시오 .

[signal] void QItemSelectionModel::currentRowChanged(const QModelIndex &current, const QModelIndex &previous)

current 항목이 변경되고, 해당 행이 previous 현재 항목의 행과 다를 경우 이 신호가 발생합니다.

항목 모델이 재설정될 때는 이 신호가 발생하지 않는다는 점에 유의하십시오.

currentChanged(), currentColumnChanged(), currentIndex(), setCurrentIndex()도 참조하십시오 .

[protected] void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelection, const QItemSelection &oldSelection)

newSelection 와 oldSelection 라는 두 선택 항목을 비교하고, 선택 해제된 항목과 선택된 항목을 포함하여 selectionChanged()를 반환합니다.

bool QItemSelectionModel::hasSelection() const

선택 모델에 선택된 항목이 하나라도 포함되어 있으면 ` true `를 반환하고, 그렇지 않으면 ` false`를 반환합니다.

[invokable] bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent = QModelIndex()) const

지정된 parent 를 사용하여 column 내의 모든 항목이 선택된 경우 true 를 반환합니다.

이 함수는 일반적으로 같은 열의 모든 항목에 대해 isSelected()를 호출하는 것보다 빠르며, 선택할 수 없는 항목은 무시된다는 점에 유의하십시오.

참고: Qt 5.15부터 parent 의 기본 인수는 빈 모델 인덱스입니다.

참고: 이 함수는 메타 객체 시스템과 QML을 통해 호출할 수 있습니다. Q_INVOKABLE 를 참조하십시오.

[invokable] bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent = QModelIndex()) const

지정된 parent 를 사용하여 row 내의 모든 항목이 선택된 경우 true 를 반환합니다.

이 함수는 일반적으로 같은 행의 모든 항목에 대해 isSelected()를 호출하는 것보다 빠르며, 선택할 수 없는 항목은 무시된다는 점에 유의하십시오.

참고: Qt 5.15부터 parent 의 기본 인수는 빈 모델 인덱스입니다.

참고: 이 함수는 메타 객체 시스템과 QML을 통해 호출할 수 있습니다. Q_INVOKABLE 를 참조하십시오.

[invokable] bool QItemSelectionModel::isSelected(const QModelIndex &index) const

주어진 모델 항목 index 이 선택된 경우 ` true `을 반환합니다.

참고: 이 함수는 메타 객체 시스템과 QML을 통해 호출할 수 있습니다. Q_INVOKABLE 를 참조하십시오.

QAbstractItemModel *QItemSelectionModel::model()

선택 모델이 조작한 항목 모델을 반환합니다.

setModel()도 참조하십시오 .

const QAbstractItemModel *QItemSelectionModel::model() const

선택 모델이 연산 대상으로 삼은 항목 모델을 반환합니다.

[signal] void QItemSelectionModel::modelChanged(QAbstractItemModel *model)

이 신호는 ` model `가 ` setModel()`를 통해 성공적으로 설정되었을 때 발생합니다.

model() 및 setModel()도 참조하십시오 .

[virtual slot] void QItemSelectionModel::reset()

선택 모델을 지웁니다. 신호를 발생시키지 않습니다.

[invokable] bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &parent = QModelIndex()) const

row 에서 지정된 parent 와 일치하는 항목이 선택된 경우 true 를 반환합니다.

참고: Qt 5.15부터 parent 의 기본 인수는 빈 모델 인덱스입니다.

참고: 이 함수는 메타 객체 시스템과 QML을 통해 호출할 수 있습니다. Q_INVOKABLE 을 참조하십시오.

[virtual slot] void QItemSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)

지정된 command 를 사용하여 항목 selection 를 선택하고, selectionChanged()를 출력합니다.

참고: 이 슬롯은 오버로드되어 있습니다. 이 슬롯에 연결하려면:

// Connect using qOverload:
connect(sender, &SenderClass::signal,
        itemSelectionModel, qOverload(&QItemSelectionModel::select));

// Or using a lambda as wrapper:
connect(sender, &SenderClass::signal,
        itemSelectionModel, [receiver = itemSelectionModel](const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) { receiver->select(selection, command); });
더 많은 예제와 방법에 대해서는 오버로드된 슬롯에 연결하기를 참조하십시오.

QItemSelectionModel::SelectionFlag도 참조하십시오 .

[virtual slot] void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)

지정된 command 를 사용하여 모델 항목 index 을 선택하고, selectionChanged()를 출력합니다.

참고: 이 슬롯은 오버로드되어 있습니다. 이 슬롯에 연결하려면:

// Connect using qOverload:
connect(sender, &SenderClass::signal,
        itemSelectionModel, qOverload(&QItemSelectionModel::select));

// Or using a lambda as wrapper:
connect(sender, &SenderClass::signal,
        itemSelectionModel, [receiver = itemSelectionModel](const QModelIndex &index, QItemSelectionModel::SelectionFlags command) { receiver->select(index, command); });
더 많은 예제와 방법에 대해서는 오버로드된 슬롯에 연결하기를 참조하십시오.

QItemSelectionModel::SelectionFlags도 참조하십시오 .

[invokable] QModelIndexList QItemSelectionModel::selectedColumns(int row = 0) const

주어진 row 내에서 모든 행이 선택된 열의 인덱스를 반환합니다.

참고: 이 함수는 메타 객체 시스템 및 QML을 통해 호출할 수 있습니다. Q_INVOKABLE 를 참조하십시오.

selectedIndexes() 및 selectedRows()도 참조하십시오 .

QModelIndexList QItemSelectionModel::selectedIndexes() const

선택된 모든 모델 항목 인덱스의 목록을 반환합니다. 이 목록에는 중복 항목이 없으며, 정렬되어 있지 않습니다.

참고: selectedIndexes 속성에 대한게터 함수입니다.

[invokable] QModelIndexList QItemSelectionModel::selectedRows(int column = 0) const

주어진 column 에서 모든 열이 선택된 행에 대한 인덱스를 반환합니다.

참고: 이 함수는 메타 객체 시스템 및 QML을 통해 호출할 수 있습니다. ` Q_INVOKABLE`을 참조하십시오.

selectedIndexes() 및 selectedColumns()도 참조하십시오 .

const QItemSelection QItemSelectionModel::selection() const

선택 모델에 저장된 선택 범위를 반환합니다.

[signal] void QItemSelectionModel::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)

이 신호는 선택 내용이 변경될 때마다 발생합니다. 선택 내용의 변경은 deselected 항목의 항목 선택과 selected 항목의 항목 선택으로 나타납니다.

현재 인덱스는 선택 상태와 독립적으로 변경된다는 점에 유의하십시오. 또한, 항목 모델이 재설정될 때는 이 신호가 발생하지 않는다는 점에도 유의하십시오.

선택된 상태는 유지되지만 인덱스가 변경된 항목은 selected 및 deselected 에 포함되지 않습니다. 따라서 선택된 항목의 인덱스만 변경되는 경우, selected 과 deselected 가 모두 비어 있는 상태에서도 이 신호가 발송될 수 있습니다.

참고: 이 신호에 직접 연결된 슬롯 내부에서는 모델(예: setData() 호출)을 수정할수 없습니다. 이 신호는 모델이 수정되는 과정(예: 행 또는 열 제거, 모델 재설정 중)에 있을 때 발산될 수있습니다 . 이러한 시점에 추가 변경을 시도하면 정의되지 않은 동작이 발생할 수 있습니다. 특히, 중첩된 수정은 QSortFilterProxyModel 에서 관리하는 매핑 구조와 같은 내부 상태를 손상시킬 수 있습니다.

참고: 속성 selectedIndexes 에 대한알림 신호입니다.

select() 및 currentChanged()도 참조하십시오 .

[virtual slot] void QItemSelectionModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)

모델 항목 index 을 현재 항목으로 설정하고, currentChanged()를 발생시킵니다. 현재 항목은 키보드 탐색 및 포커스 표시에 사용되며, 선택된 항목과는 별개이지만, 선택된 항목이 현재 항목이 될 수도 있습니다.

지정된 command 에 따라 index 도 현재 선택 항목의 일부가 될 수 있습니다.

currentIndex() 및 select()도 참조하십시오 .

void QItemSelectionModel::setModel(QAbstractItemModel *model)

모델을 ‘ model ’로 설정합니다. 이때 ‘ modelChanged()’ 신호가 발생합니다.

model() 및 modelChanged()도 참조하십시오 .

© 2026 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.