Solved How to get parent ui in custom class ?
-
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()));
} -
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
-
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()));
...
} -
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