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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:48:32+00:00 2026-06-15T22:48:32+00:00

In Qt Creator, I have a couple of widgets declared like so: Header File:

  • 0

In Qt Creator, I have a couple of widgets declared like so:

Header File:

    class MapViewer : public QGraphicsView
{
    Q_OBJECT

public:
    explicit MapViewer(QGraphicsScene *scene, QWidget *parent = 0);
    ~MapViewer();

public slots:
    void mousePressEvent(QMouseEvent *event);

};

// Declaration for the map editor window.
class MapEditor : public QMainWindow
{
    Q_OBJECT

public:
    explicit MapEditor(QWidget *parent = 0);
    ~MapEditor();

public:
    QLayout *editorLayout;
    QPushButton *btn;
    QGraphicsScene *mapScene;
    MapViewer *mapView;

private:
    Ui::MapEditor *ui;
};

CPP File:

  MapEditor::MapEditor(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MapEditor)
{

    ui->setupUi(this);
    this->setWindowTitle("2DXY :: Map Editor");
    this->setGeometry(10,10,1170,750);
    editorLayout = new QVBoxLayout; // Create a new layout
    this->setLayout(editorLayout); // Set the widget's layout to our newly created layout.

    mapScene = new QGraphicsScene(); // Create a new graphics scene to draw upon.

    mapView = new MapViewer(mapScene,this); // Create a new graphics view to display our scene - set its parent to 'this' so that it doesn't open in a new window.
    mapView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    mapView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    mapView->setGeometry(20,20,1178,546); // Width first, then height.

AND:

void MapViewer::mousePressEvent(QMouseEvent *event)
{
    // Show an empty message box, just to check that the event handler works!
    QMessageBox *notification = new QMessageBox();
    notification->show();
    notification->exec();
    // Some how access the same QGraphicsScene and View (mapScene, mapView) as above, so
    // I can update their contents on the open form / window.

}

And as you can see, I wish to access the Graphics Scene again to update it, then redraw it (or whatever). But I’m not able to access the graphics scene at all, despite a few hours of trial and error with declaring widgets in different ways.

I know that the listener itself works, because if it’s set to open a new message box, or output to the debug window, then it works, it’s just that I can’t access the widgets I’ve already defined.

I feel that there is a (relatively) easy solution to this problem, and that I’m just missing something obvious.

  • 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-15T22:48:33+00:00Added an answer on June 15, 2026 at 10:48 pm
    void MapViewer::mousePressEvent(QMouseEvent *event)
    {
        // Show an empty message box, just to check that the event handler works!
        QMessageBox *notification = new QMessageBox();
        notification->show();
        notification->exec();
    
        //  To add something whenever the user clicks, you don't need the view,
        //  just the scene.
        scene()->addItem( new MyItem() );
    }
    

    Remember MapViewer derives from QGraphicsView and the view must know about the scene it belongs to – so it has a scene() method to return it, which you inherited.

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

Sidebar

Related Questions

I have a Class called Song with Inner class Creator . Below is the
I have a DLL made in C#, this DLL contains some clases like Creator.
The Qt Creator have a neat feature I really like. When I'm typing obj.method,
I have used Qt Creator and created my.exe file and a new extension .newext
I have the following class in my models.py class Story(models.Model): title = models.CharField(max_length=60) creator
I have a simple module created with the Magento Module Creator with a couple
I have a User class that has a property called Creator which is of
I have site which is a creator of smaller websites, and I'd like to
I have a qmake file generated by Qt creator. I am modifying it but
I have Qt creator installed in my OpenSuse. I would like to view all

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.