Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get parent ui in custom class ?
Forum Updated to NodeBB v4.3 + New Features

How to get parent ui in custom class ?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    MainWindow
    {
    ui->setupUi(this);
    imageWidget = new ImageWidget;
    scrollArea = new QScrollArea;
    scrollArea->setWidget(imageWidget);
    scrollArea->widget()->setMinimumSize(600,500);
    setCentralWidget(scrollArea);
    }

    void ImageWidget::mouseMoveEvent(QMouseEvent *e)
    {
    ui->statusBar->showMessage(QString::number(e->pos().x())+","+QString::number(e->pos().y()));
    }

    https://github.com/sonichy

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by Eddy
      #2

      Hi Sonichy,

      If I understand your question correctly you want information from you imageWidget to be displayed in the statusbar of your MainWindow.

      You can do this with the signal slot mechanism in Qt;

      in your mousMoveEvent emit a signal with your QString
      connect the signal to ui->statusBar in your Mainwindow constructor like this :

      connect(this, SIGNAL(myMessage(QString)), ui->statusBar, SLOT(showMessage(QString)));
      

      And you should be good to go.

      Eddy

      Qt Certified Specialist
      www.edalsolutions.be

      sonichyS 1 Reply Last reply
      1
      • EddyE Eddy

        Hi Sonichy,

        If I understand your question correctly you want information from you imageWidget to be displayed in the statusbar of your MainWindow.

        You can do this with the signal slot mechanism in Qt;

        in your mousMoveEvent emit a signal with your QString
        connect the signal to ui->statusBar in your Mainwindow constructor like this :

        connect(this, SIGNAL(myMessage(QString)), ui->statusBar, SLOT(showMessage(QString)));
        

        And you should be good to go.

        Eddy

        sonichyS Offline
        sonichyS Offline
        sonichy
        wrote on last edited by
        #3

        After compare what you say and someone's code, I finally made it !
        This is custom signal model, your code is confused and has one error, I write it clearly below:

        MainWindow
        {
        ...
        ImageWidget *imageWidget = new ImageWidget;
        QScrollArea *scrollArea = new QScrollArea;
        scrollArea->setWidget(imageWidget);
        scrollArea->widget()->setMinimumSize(600,500);
        setCentralWidget(scrollArea);
        connect(imageWidget, SIGNAL(statusbarMessage(QString)), ui->statusBar, SLOT(showMessage(QString)));
        ...
        }

        imagewidget.h
        {
        ...
        signals:
        void statusbarMessage(QString);
        ...
        }

        ImageWidget::::mouseMoveEvent(QMouseEvent *e)
        {
        ...
        emit statusbarMessage(QString::number(e->pos().x())+","+QString::number(e->pos().y()));
        ...
        }

        https://github.com/sonichy

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          Hi sonichy,

          The code I wrote was just an example to give you the general idea ;-)

          I'm glad you could solve your issue. Could you please mark the topic as solved by using the Topic tools button on the right?

          Eddy

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved