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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:19:38+00:00 2026-06-16T22:19:38+00:00

Situation : I have a Dialog class in QT on which I draw a

  • 0

Situation:

I have a Dialog class in QT on which I draw a raster of squares. The squares are implemented in the MySquare class (MySquare: QGraphicsItem).

Inside the MySquare there are a number of functions (mysquare.h protected: )

    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);

When I click on a square it gives me the relative coordinates of the square using the following function.

void MySquare::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    update();
    QGraphicsItem::mousePressEvent(event);
    qDebug() << "mouse Pressed";
    qDebug() << "coordinates:";
    qDebug() << "X:"<< x/w << " Y:" << y/h ;
}

enter image description here

Where x and y are the x and y position in the raster and w and h stand for width and height

However my question is how can I let my Dialog class know what square was clicked on?

  • 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-16T22:19:40+00:00Added an answer on June 16, 2026 at 10:19 pm

    You can communicate between MySquare and and your Dialog by means of the signal/slot mechanism of Qt.
    When a square gets clicked, it emits a signal, and the Dialog has a slot that is connected to that signal.

    To identify which square sent the signal, there are several possibilities:

    • The coordinates of the square are passed along in the signal
    • The this pointer of the MySquare that emits the signal is passed along
    • In the slot, you can use the sender function to determine who emitted the signal.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation : I have a Dialog class in Qt on which I draw a
I have following situation - Have a MongoService class, which reads host, port, database
I am in a situation. I have a dropdownlist inside jquery dialog. On click
I have this situation: http://jsfiddle.net/bRDgK/3/ In this situation I have a modal dialog with
Following situation: I have a JFrame and call JOptionPane.showInputDialog(test) . The modal dialog will
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
Situation: I have an index page which loads pages into it with ajax as
i have situation like this: class IData { virtual void get() = 0; virtual
So, I'll explain my situation. I have a Service which is catching the events
I have a situation where I need to know which features are to be

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.