| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
                                        Tags
                                        
                                    
                                        
                                    - AWS
- 도커
- driver
- ubuntu
- 드라이버
- 패키지
- 루비
- ssh
- window size
- RUBY
- Linux
- 방화벽체크
- VIM
- docker container
- sudo
- VPN
- VMware
- QT
- docker
- Openswan
- docker-compose
- Chef
- 우분투
- ssh command
- 리눅스
- docker registry
- opsworks
- port
- golang
- DevOps
- Today
- Total
구리의 창고
QT Programming - QTreeView 의 checkbox 클릭 여부 확인하기 본문
QTreeView를 사용 할 때 checkbox를 사용하다보면 문제가 생긴다.
아이템과 마우스를 처리하면서 clicked 시그날을 사용 할 때가 있는데,
문제는 item을 클릭할 때와 checkbox를 클릭 할 때 체크되게 하는 경우이다.
checkbox도 item으로 인식하기 때문에 check와 click이 같이 발생하게 되는것이다.
그래서 시그날이 발생하는 순서를 살펴봤다.
* clicked 의 경우
mousePressEvent() -> mouseReleaseEvent()
=> clicked 발생
* checked 의 경우 (시그날은 아니지만)
mouseReleaseEvent()
=> checked 발생
위와 같이 mouseReleaseEvent() 시에 checked와 clicked 가 같이 발생하게 되는 것이다.
이러면 checked로 체크 후에 다시 clicked에서 체크 해제하는 바람에 아무 것도 일어나지 않는 것처럼 보이게 된다.
(순서는 바꼈을지도 모른다)
그러므로 mouseReleaseEvent() 를 오버로딩해서 체크박스 클릭여부를 확인 후 ignore 시키고 clicked만 발생시켜준다.
 
            
                            
        아이템과 마우스를 처리하면서 clicked 시그날을 사용 할 때가 있는데,
문제는 item을 클릭할 때와 checkbox를 클릭 할 때 체크되게 하는 경우이다.
checkbox도 item으로 인식하기 때문에 check와 click이 같이 발생하게 되는것이다.
그래서 시그날이 발생하는 순서를 살펴봤다.
* clicked 의 경우
mousePressEvent() -> mouseReleaseEvent()
=> clicked 발생
* checked 의 경우 (시그날은 아니지만)
mouseReleaseEvent()
=> checked 발생
위와 같이 mouseReleaseEvent() 시에 checked와 clicked 가 같이 발생하게 되는 것이다.
이러면 checked로 체크 후에 다시 clicked에서 체크 해제하는 바람에 아무 것도 일어나지 않는 것처럼 보이게 된다.
(순서는 바꼈을지도 모른다)
그러므로 mouseReleaseEvent() 를 오버로딩해서 체크박스 클릭여부를 확인 후 ignore 시키고 clicked만 발생시켜준다.
void OrganizationTreeView::mouseReleaseEvent(QMouseEvent* event)
{
	//whether checkbox is clicked.
	QModelIndex index = indexAt(event->pos());
	if(index.isValid())
	{
		QRect vrect = visualRect(index);
		int itemIndentation = vrect.x() - visualRect(rootIndex()).x();
	
		QRect rect = QRect(header()->sectionViewportPosition(0) + itemIndentation 
			, vrect.y(), style()->pixelMetric(QStyle::PM_IndicatorWidth), vrect.height());
		if(rect.contains(event->pos()))
		{
			//prevent from emitting checked and clicked and then emit only clicked.
			emit clicked(index);
			event->ignore();
		}
		else
		{
			QTreeView::mouseReleaseEvent(event);
		}
	}
}
'QT' 카테고리의 다른 글
| QT Programming - QModelIndex 에서 item 정보 가져오기 (0) | 2011.09.06 | 
|---|---|
| QT Programming - QTableView column width 변경 (0) | 2011.09.06 | 
| QT Programming - 우클릭 시 clicked 시그날 발생 막기 (0) | 2011.09.05 | 
| QT Programming - QTextEdit 에 Drag and Drop 으로 파일 넣기 (0) | 2011.08.31 | 
| QT Programming - 'QObject::QObject' cannot access private member declared in class 'QObject' (0) | 2011.08.26 | 
                          Comments