标签: mousepress

Libgdx为什么我的按钮在鼠标点击时没有响应

为什么我的TextButtonlibgdx没有响应点击?

我有一个按钮,这个按钮有一个监听器,但它没有响应.该按钮正在显示,但它不会响应鼠标点击.

public MyStage extends Stage {
     ...
     next.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
        {
            Gdx.app.log(ApothecaryGame.LOG, "Pressed: Next button.");
            return true;
        }
        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            Gdx.app.log( ApothecaryGame.LOG, "Released: Next button.");
            super.touchUp( event, x, y, pointer, button );
            nextPage();
        }
    } );
    this.addActor(next);
}
Run Code Online (Sandbox Code Playgroud)

java button mousepress libgdx

4
推荐指数
1
解决办法
5770
查看次数

使用 Qt 在 QGraphicsScene 中画线

我画线有问题。当鼠标移动缓慢时效果很好,但是当鼠标移动得更快时,会出现一些间隙,我不知道为什么。这是代码:

if(QEvent::MouseButtonPress&&event->buttons()==Qt::LeftButton){
QPointF pt=mapToScene(event->pos());
        band->setGeometry(0,0,0,0);
         band->hide();
        band->update();
         this->scene()->addLine(pt.x(),pt.y(),pt.x(),pt.y(),QPen(color, size));
    qDebug()<<event->pos();
}
Run Code Online (Sandbox Code Playgroud)

这是一个屏幕截图:

在此处输入图片说明

左边画得慢,右边画得快。

qt mousepress qgraphicsscene

4
推荐指数
1
解决办法
4510
查看次数

视图中的MousePressEvent和Qt中的项目

我有一个自定义QGraphicsView和一个自定义QGraphicsItem.如果我点击该项目,我希望项目处理我的点击,否则我希望点击由视图处理.

但是当我点击该项目时,该项目处理点击.还行吧.但是,如果我点击其他地方,则根本不会处理点击.我的类中与mouseEvents有关的所有代码如下.

class CustomView : public QGraphicsView
{
    Q_OBJECT

public:

    void mousePressEvent(QGraphicsSceneMouseEvent *event);

};

void CustomView::mousePressEvent(QGraphicsSceneMouseEvent *event){
    cout << "pressing in view";
}

class CustomItem : public QGraphicsItem
{
public:
    CustomItem(CustomView* widget)
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
};

CustomItem::CustomItem(CustomView* widget){
    setFlag(ItemIsSelectable);
    setFlag(ItemIsMovable);
}

void CustomItem::mousePressEvent(QGraphicsSceneMouseEvent *event){
    cout << "pressing in item";
}
Run Code Online (Sandbox Code Playgroud)

似乎当我从CustomItem类中删除mousePressEvent函数并在CustomView中将mousePressEvent函数更改为:

void CustomView::mousePressEvent(QMouseEvent *event){
    cout << "pressing in view";
}
Run Code Online (Sandbox Code Playgroud)

CustomView处理所有mouseEvents.

如何让CustomItem处理项目中的点击,而CustomView处理所有其他点击?

谢谢.

编辑

所以现在我把它改成了:

    class CustomView : public QGraphicsView
{
    Q_OBJECT

public:

};

 class CustomScene : public QGraphicsScene
{ …
Run Code Online (Sandbox Code Playgroud)

qt mouseevent mousepress

3
推荐指数
1
解决办法
8613
查看次数

如何通过单击 Qt 中的 qgraphicsscene 获取确切位置

我正在编写代码以从文件加载图像并对这个图像做了一些编辑(改变一些像素的值),放大或缩小,然后保存图像。另外,我想知道与点击 qgraphicsscen 相关联的原始图像中的位置。到目前为止,我找不到任何有用的功能。

我加载图像的代码:

qgraphicsscene = myqgraphicsview->getScene();
qgraphicsscene->setSceneRect(image->rect());
myqgraphicsview->setScene(qgraphicsscene);
qgraphicsscene->addPixmap(QPixmap::fromImage(*image)); // this is the original image
Run Code Online (Sandbox Code Playgroud)

我的编辑代码:

mousePressEvent(QMouseEvent * e){
QPointF pt = mapToScene(e->pos());
scene->addEllipse(pt.x()-1, pt.y()-1, 2.0, 2.0,
QPen(), QBrush(Qt::SolidPattern));}
Run Code Online (Sandbox Code Playgroud)

我想知道 e->pos() 与原始图像中的确切位置之间的关系。

qt qpixmap mousepress qgraphicsscene

3
推荐指数
1
解决办法
2979
查看次数

单击QPushButton setDown

QPushButton被点击时,我希望它保持向下压,直到再次点击.

void MainWindow::itemClicked(){

    QPushButton *clickedItem = qobject_cast<QPushButton *>(sender());

    qDebug() << clickedItem->isDown();

    if(!clickedItem->isDown())
        clickedItem->setDown(true);
    else
        clickedItem->setDown(false);
}
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用.这将导致无限期按下按钮.

clickedItem->isDown() 总是假的.

c++ qt click mousepress qpushbutton

3
推荐指数
1
解决办法
6430
查看次数

mousepressevent的问题

我刚问了一个类似的问题但是(对不起!)我想我需要更多的帮助.pyqt中的信号有问题.让我发布整个代码,它不长,我更容易解释...

from PyQt4 import QtGui, QtCore, Qt
import time
import math

class FenixGui(QtGui.QWidget):

    def backgroundmousepressevent(self, event):
        print "test 1"
        self.offset = event.pos()


    def backgroundmousemoveevent(self, event):
        print "test 2"
        x=event.globalX()
        y=event.globalY()
        x_w = self.offset.x()
        y_w = self.offset.y()
        self.move(x-x_w, y-y_w)


    def __init__(self):
        super(FenixGui, self).__init__()

        # setting layout type
        hboxlayout = QtGui.QHBoxLayout(self)
        self.setLayout(hboxlayout)

        # hiding title bar
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)

        # setting window size and position
        self.setGeometry(200, 200, 862, 560)
        self.setAttribute(Qt.Qt.WA_TranslucentBackground)
        self.setAutoFillBackground(False)

        # creating background window label
        backgroundpixmap = QtGui.QPixmap("fenixbackground.png")
        self.background = QtGui.QLabel(self)
        self.background.setPixmap(backgroundpixmap)
        self.background.setGeometry(0, …
Run Code Online (Sandbox Code Playgroud)

python signals pyqt mouseevent mousepress

2
推荐指数
1
解决办法
7113
查看次数

获取鼠标在QLabel中的位置

在QLabel中获得posa 的最佳(最简单)方法mousePressedEvent是什么?(或者基本上只获取相对于QLabel小部件的鼠标点击位置)

编辑

我尝试了Frank以这种方式建议的内容:

bool MainWindow::eventFilter(QObject *someOb, QEvent *ev)
{
if(someOb == ui->label && ev->type() == QEvent::MouseButtonPress)
{
    QMouseEvent *me = static_cast<QMouseEvent *>(ev);
    QPoint coordinates = me->pos();
    //do stuff
    return true;
}
else return false;
}
Run Code Online (Sandbox Code Playgroud)

但是,我invalid static_cast from type 'QEvent*' to type 'const QMouseEvent*'在我尝试声明的行上收到编译错误me.我在这里做错了什么想法?

c++ qt point-of-sale mousepress

0
推荐指数
1
解决办法
9967
查看次数