Results 1 to 2 of 2

Thread: How to display contents in Ui from another class

  1. #1
    Join Date
    Dec 2012
    Posts
    45
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default How to display contents in Ui from another class

    i have two classes one is main window and i promoted my custom widget to the other class. Now i want to show the coordinates of the Custom Widget in a line edit which is in my main window on mouse move event. I implimented the mouse move event and it is showing coordinate on the tool tip i.e where ever my cursor point in the custom widget coordinate are displayed along the cursor.
    Now i want these coordinates to be displayed in a list box.
    here is my code :
    SRP_Plot_widget
    void SRP_Plot_widget::mouseMoveEvent ( QMouseEvent * event )
    {
    MainWindow obj;


    QPointF position = event->posF();
    double x = event->pos().x()/SRP_scaleX;
    double y= event->pos().y()/SRP_scaleY;

    QToolTip::showText(event->globalPos(), QString::number(x ) + ", " + QString::number( y ));
    }

    now i want this information in lie edit which is in mainwindow.

  2. #2
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to display contents in Ui from another class

    Hello,

    You want to display the content in your main window.
    You can use the SIGNAL and SLOT feature of Qt.

    1. Connect your SRP_Plot_widget class signal which contains the data you want to display with your mainwindow SLOT.
    eg,
    Qt Code:
    1. // here 'this' pointer is the pointer of mainwindow
    2. QObject::connect(SRP_Plot_Widget_Object, SIGNAL(customSignal(QString)), this, SLOT(customDisplayData(QString)));
    To copy to clipboard, switch view to plain text mode 

    2. Just emit a signal from your SRP_Plot_widget class whenever mouse moves or whenever you want to display the changed data.
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

Similar Threads

  1. Replies: 3
    Last Post: 19th December 2011, 16:09
  2. Display contents of .txt file
    By karmo in forum Newbie
    Replies: 17
    Last Post: 23rd January 2010, 20:39
  3. Replies: 0
    Last Post: 9th April 2009, 06:35
  4. Replies: 6
    Last Post: 9th January 2008, 15:56
  5. Replies: 4
    Last Post: 10th December 2006, 09:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.