2012-11-21 9 views
2

QListWidget에 사용자 정의 메뉴를 연결하는 데 문제가 있습니다. 연결 함수는 false를 반환합니다. 다음은 코드입니다.Qt로 연결하는 사용자 정의 컨텍스트 메뉴

MainWindow이라는 메인 윈도우 클래스가 있습니다. 생성자에서 나는 notesWidgetQListWidget을 언급이 줄

connect(ui->notesWidget, SIGNAL(customContextMenuRequested(QPoint &)), 
     this, SLOT(contextMenuforNotesArea(QPoint &))); 

있습니다.

ContextMenuforNotesArea(QPoint &)

내가 또한 폼 디자이너를 통해 customContextMenulistWidget에서 속성 contextMenu을 변경 한이

class MainWindow : public QMainWindow 
{ 
public slots: 
    void contextMenuforNotesArea(QPoint &pos); 
}; 

void MainWindow::contextMenuforNotesArea(const QPoint &pos){ 
    QMessageBox::information(this, "a", "the function has been finally called"); 
    QMenu contextMenu(tr("Context menu"), this); 
    contextMenu.addAction(new QAction(tr("Hello"), this)); 
    contextMenu.exec(mapToGlobal(pos)); 
} 

과 같이 정의된다. 생성자에서 연결을 수행 할 때 헤더 파일 또한

void contextMenuforNotesArea(const QPoint &pos); 

확인에 다음과 같이

+1

의 호출 후에 그것을 할 당신이'connect'를 밟을 때 디버그 출력을합니까? 'connect'가 실패하면 디버그 출력에 유용한 정보를 제공합니다. – sashoalm

답변

0
이 SLOT 서명을 변경

, 당신은 당신이 어떤을받을 수 있나요 setupUi

+0

그래, 고마워 지금은 그냥 마우스 위에 약간의 메뉴가 만들어졌다.이 함수는 무효이다. MainWindow :: contextMenuforNotesArea (const QPoint & pos) {QMenu contextMenu (tr ("Context menu"), this); contextMenu.addAction (새 QAction (tr ("Hello"), this)); contextMenu.exec (mapToGlobal (pos)); } 어쨌든 엉망이지만 유감스럽게도 왜 코드가 코드로 표시되지 않았는지 모르겠다. 나는 줄 4 칸을 썼다 :/ – Aspect

+0

위젯의'mapToGlobal (const QPoint & pos)' 이 경우'contextMenu.exec (mapToGlobal (pos))'은'contextMenu.exec (ui-> notesWidget-> mapToGlobal (pos))'로 변경되어야한다. 작동하는지 확인 – warunanc

+0

오, 고마워. – Aspect

관련 문제