QListWidget
에 사용자 정의 메뉴를 연결하는 데 문제가 있습니다. 연결 함수는 false를 반환합니다. 다음은 코드입니다.Qt로 연결하는 사용자 정의 컨텍스트 메뉴
MainWindow
이라는 메인 윈도우 클래스가 있습니다. 생성자에서 나는 notesWidget
가 QListWidget
을 언급이 줄
connect(ui->notesWidget, SIGNAL(customContextMenuRequested(QPoint &)),
this, SLOT(contextMenuforNotesArea(QPoint &)));
있습니다.
ContextMenuforNotesArea(QPoint &)
customContextMenu
에
listWidget
에서 속성
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);
확인에 다음과 같이
의 호출 후에 그것을 할 당신이'connect'를 밟을 때 디버그 출력을합니까? 'connect'가 실패하면 디버그 출력에 유용한 정보를 제공합니다. – sashoalm