문서의 선택한 두 판 사이의 차이를 보여줍니다.
— |
kb:qttips [2014/11/08 13:03] (현재) |
||
---|---|---|---|
줄 1: | 줄 1: | ||
+ | ====== QTreeWidget 그리드 라인 그리기 ====== | ||
+ | http://qt-project.org/forums/viewthread/20329 | ||
+ | <code cpp> | ||
+ | #pragma once | ||
+ | |||
+ | class CTreeWidgetDelegate : public QStyledItemDelegate | ||
+ | { | ||
+ | Q_OBJECT | ||
+ | |||
+ | public: | ||
+ | explicit CTreeWidgetDelegate(QObject* parent = 0) | ||
+ | : | ||
+ | QStyledItemDelegate(parent) | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex &index) const | ||
+ | { | ||
+ | QStyledItemDelegate::paint(painter,option,index); | ||
+ | |||
+ | QPen pen; | ||
+ | pen.setWidth(1); | ||
+ | pen.setColor(QColor(200, 200, 200)); | ||
+ | pen.setStyle(Qt::DotLine); | ||
+ | painter->setPen(pen); | ||
+ | |||
+ | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); | ||
+ | painter->drawLine(option.rect.topRight(), option.rect.bottomRight()); | ||
+ | } | ||
+ | }; | ||
+ | ... | ||
+ | MyTreeWidget->setItemDelegate(new CTreeWidgetDelegate); | ||
+ | </code> | ||
+ | |||
+ | ====== 컨텍스트 메뉴 보여주기 ====== | ||
+ | http://www.ffuts.org/blog/right-click-context-menus-with-qt/ | ||
+ | <code cpp> | ||
+ | // myWidget is any QWidget-derived class | ||
+ | myWidget->setContextMenuPolicy(Qt::CustomContextMenu); | ||
+ | connect(myWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowContextMenu(const QPoint&))); | ||
+ | ... | ||
+ | void MyClass::ShowContextMenu(const QPoint& pos) // this is a slot | ||
+ | { | ||
+ | // for most widgets | ||
+ | QPoint globalPos = myWidget->mapToGlobal(pos); | ||
+ | // for QAbstractScrollArea and derived classes you would use: | ||
+ | // QPoint globalPos = myWidget->viewport()->mapToGlobal(pos); | ||
+ | |||
+ | QMenu myMenu; | ||
+ | myMenu.addAction("Menu Item 1"); | ||
+ | // ... | ||
+ | |||
+ | QAction* selectedItem = myMenu.exec(globalPos); | ||
+ | if (selectedItem) | ||
+ | { | ||
+ | // something was chosen, do stuff | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | // nothing was chosen | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ====== QGraphicsView ====== | ||
+ | 현재 보고 있는 중심점 | ||
+ | <code cpp> | ||
+ | QPointF center = MainView->mapToScene(MainView->viewport()->rect().center()); | ||
+ | </code> | ||
+ | |||
+ | ====== IME ====== | ||
+ | * Microsoft IME 2007이 기본 IME로 설정되어 있는 경우, TextEdit 시리즈들이 정상적으로 동작하지 않는다. | ||
+ | * 한글 입력 중에 스페이스나 엔터키를 눌러보면 문제가 뭔지 알 수 있다. | ||
+ | * 소스 차원에서의 깔끔한 해결책은 찾지 못했으며, "Microsoft 입력기"를 기본 IME로 선택해주면 해결할 수 잇다. | ||
+ | |||
+ | ====== COM ====== | ||
+ | * QApplication 객체 내부에서 OleInitialize, OleUnintialize 함수를 호출한다. | ||
+ | * 이로 인해 QApplication 객체가 소멸됨과 동시에 모든 COM 오브젝트들의 레퍼런스가 날아가 버린다. -> Release 호출시 AV 발생! | ||
+ | * 왠지 모르겠으나, QApplication 객체 생성 전에 CoInitializeEx 함수를 호출하면 클립보드가 정상적으로 동작하지 않는다. | ||
+ | |||
+ | ---- | ||
+ | * see also [[Qt]] | ||