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 8520791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:37:48+00:00 2026-06-11T06:37:48+00:00

pretty new to using Qt. I have a custom widget that i need to

  • 0

pretty new to using Qt. I have a custom widget that i need to have recieving button presses, then from that button press finding the position of the mouse on the widget.
Unfortunately, currently the mousePressEvent(QMouseEvent *me) doesn’t seem to be working correctly.
So i’m wondering what exactly i’m doing wrong, code below;

Header File:

#ifndef TILESHEETPANE_H
#define TILESHEETPANE_H

#include <QWidget>
#include "global.h"

class tileSheetPane : public QWidget
{
   Q_OBJECT

 public:
     tileSheetPane(int scnWidth, Global *global, QWidget *parent);

 protected:
     void mousePressEvent(QMouseEvent *me);
     void paintEvent(QPaintEvent *);

 private:
     Global *tempGlobal;
     QPoint cursorPos;
     int tileSheetPaneWidth, tileSheetPaneHeight, renderOffsetY;
 };

 #endif // TILESHEETPANE_H

Src File:

   #include <QPainter>
   #include <QMouseEvent>
   #include "tilesheetpane.h"

   //Constructor & Paint Event .. 

   void tileSheetPane::mousePressEvent(QMouseEvent *me)
   {
        cursorPos = me->pos();
   }

CursorPos’s values just say at their initialized 0. So any help would be greatly appreciated :), as i said, pretty new to using QT only started probably 2 days ago so i’m still trying to figure out things :D.

Edit;
So after trying out some of the suggestions in the comments, nothing seems to be working. I do indeed have setMouseTracking(true) but still nothing. I inserted a qDebug call into the function as suggested and it seems that the mousePressEvent never gets called.

 void tileSheetPane::mousePressEvent(QMouseEvent *me)
 {
     cursorPos = me->pos();

     //These Never Show Up!
     qDebug() << me->pos().x();
     qDebug() << me->pos().y();
 }

Something perhaps is blocking or stopping this being called but im not sure what it could be?

  • 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-06-11T06:37:50+00:00Added an answer on June 11, 2026 at 6:37 am

    So i just couldn’t get the mouse clicking working, so after doing some searching on google, i eventually found the following video;
    http://www.youtube.com/watch?v=E29KiTRYpjk

    As my widget is rather small anyway, i basically just re-did the entire thing. But it was worth it.
    Essentially i deleted my old files, created a Qt Designer Form, added in a new widget into my mainWindow.ui file, promoted it to use “tileSheetPane” and that’s it. Works perfectly now :D.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still pretty new to using jQuery to do anything, but I have
I am pretty much new to using SQL Server 2000. I have been using
Helo, I am pretty new to Ruby (using 1.8.6) and need to know whether
I have a legacy database with a pretty evil design that I need to
I'm pretty new to powershell. I've built a custom cmdlet. I already have it
I'm pretty new to using MVC3 so hopefully the terms I'm using are all
i'm pretty new at using C++ and I'm actually stopped at a problem. I
I'm pretty new to WPF and using the MVVM design pattern. To help learn
I'm pretty new to c++ and I'm using libcurl to make an http request
I'm pretty new to APEX ( well, just started using it ~an hour ago),

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.