Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6347955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:19:32+00:00 2026-05-24T21:19:32+00:00

I just asked a similar question but (sorry!) I think I’ll need more help.

  • 0

I just asked a similar question but (sorry!) I think I’ll need more help. I have a problem with signals in pyqt. Let me post the whole code, it isn’t long and it is easier for me to explain…

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, 0, 862, 560)

        # making window draggable by the window label
        self.connect(self.background,QtCore.SIGNAL("mousePressEvent()"),         self.backgroundmousepressevent)
        self.connect(self.background,QtCore.SIGNAL("mouseMoveEvent()"), self.backgroundmousemoveevent)


        # fenix logo
        logopixmap = QtGui.QPixmap("fenixlogo.png")
        self.logo = QtGui.QLabel(self)
        self.logo.setPixmap(logopixmap)
        self.logo.setGeometry(100, 100, 400, 150)


def main():

    app = QtGui.QApplication([])
    exm = FenixGui()
    exm.show()
    app.exec_()


if __name__ == '__main__':
    main()

All right, so this is the code, it’s just a simple gui that I wanted to make draggable around the screen clicking and dragging on any place in the background. My problem is: backgroundmousepressevent and backgroundmousemoveevent DON’T get fired when i press or move the button. So I wonder: where’s the error? Did I mispell something or what? Thank you very much!

Matteo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:19:33+00:00Added an answer on May 24, 2026 at 9:19 pm

    In Qt, events are different from signals and slots. Events are represented by QEvent objects that are passed to the event() method of QObjects, where they are typically dispatched to specialized methods such as mousePressEvent and mouseMoveEvent. Since they are not signals, you cannot connect them to slots.

    Instead, just re-implement event functions to do custom things. Make sure to call the original implementation with super, though, unless you know what you are doing.

    def mousePressEvent(self, event):
        super(FenixGui, self).mousePressEvent(event)
        print "test 1"
        self.offset = event.pos()
    
    def mouseMoveEvent(self, event):
        super(FenixGui, self).mouseMoveEvent(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)
    

    Typically, Qt will warn you when trying to connect to non-existing signals, by writing a warning message to the console. Additionally, you can prevent this situation by using new-style signals and slots instead of the old-style, more C++-ish SIGNAL() function:

    lineEdit = QtGui.QLineEdit()
    lineEdit.valueChanged.connect(self.myHandlerMethod)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem similar to this question which was previously asked but my
In another question , I asked something similar but I ended up just posting
I have a similar question to the one I just asked. I'm trying to
I have just asked this question an hour ago but with regards to IE8
I asked a similar question a few hours ago, but I think there was
I've asked a similar question before but I'm just having a hard time wrapping
I asked a similar question yesterday but still having a slight problem on output.
I had asked a similar question a few days ago but think I was
I have asked a similar question before here , but after much thought, and
I have asked a similar question before, but I didn't have a firm grasp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.