PDA

View Full Version : How to display contents in Ui from another class



shivendra46d
19th August 2013, 10:42
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.

karankumar1609
19th August 2013, 11:37
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,


// here 'this' pointer is the pointer of mainwindow
QObject::connect(SRP_Plot_Widget_Object, SIGNAL(customSignal(QString)), this, SLOT(customDisplayData(QString)));


2. Just emit a signal from your SRP_Plot_widget class whenever mouse moves or whenever you want to display the changed data.