• 6121阅读
  • 4回复

怎样使QMainWindow上的QGraphicsView在鼠标移动时发送信号 [复制链接]

上一主题 下一主题
离线tan_tan_1
 
只看楼主 倒序阅读 楼主  发表于: 2011-06-23

我现在在一个QMainWindow上放了一个QGraphicsView和一个Qlable我现在希望在鼠标处在QGraphicsView上的时候QLable显示鼠标的x,y坐标。
我现在的做法是继承QGraphicsView实现自己的类,信号,然后重写mouseMoveEvent,在mouseMoveEvent中emit自己的一个signal函数,使用qDebug可以看到输出的x,y坐标,但是在QMainWindow中使用connect连接时候,说no such signal ,没有我在QGraphicsView中写的signal。
不知道还有什么办法
离线songxue3073
只看该作者 1楼 发表于: 2011-06-23
你自己写的使用信号和槽的类中加“Q_OBJECT”宏了吗?
离线tan_tan_1
只看该作者 2楼 发表于: 2011-06-23
引用第1楼songxue3073于2011-06-23 15:29发表的  :
你自己写的使用信号和槽的类中加“Q_OBJECT”宏了吗?


我是从QGraphicsView继承的,怎么会没有,我还专门试着加了一下,就就编译出错了
离线听雨

只看该作者 3楼 发表于: 2011-06-23
做了个测试,结果正常。。
  1. #ifndef COORX_H
  2. #define COORX_H
  3. #include <QtGui/QMainWindow>
  4. #include "ui_coorx.h"
  5. class XGraphicsView;
  6. class XLabel;
  7. class coorx : public QMainWindow,
  8.     public Ui_coorxClass
  9. {
  10.     Q_OBJECT
  11. public:
  12.     coorx(QWidget *parent = 0, Qt::WFlags flags = 0);
  13.     ~coorx();
  14. private:
  15.     //Ui::coorxClass ui;
  16.     XGraphicsView *m_pGraphicsView;
  17.     XLabel *m_pLabel;
  18. };
  19. #endif // COORX_H
  1. #include "coorx.h"
  2. #include "graphicsview.h"
  3. #include "label.h"
  4. coorx::coorx(QWidget *parent, Qt::WFlags flags)
  5.     : QMainWindow(parent, flags)
  6. {
  7.     setupUi(this);
  8.     m_pGraphicsView = new XGraphicsView(graphicsView);
  9.     m_pLabel = new XLabel(label);
  10.     connect(m_pGraphicsView, SIGNAL(sendCoor(int, int)), m_pLabel, SLOT(getCoor(int, int)));
  11. }
  12. coorx::~coorx()
  13. {
  14. }



离线tan_tan_1
只看该作者 4楼 发表于: 2011-06-24
用signal是在搞不定,只好将QLable传给QGraphicsView在mouseMoveEvent中去设置QLable的text
快速回复
限100 字节
 
上一个 下一个