[SOLVED] Cast event when window size is changed
-
@Bremenpl Re-implement resizeEvent inside the mainwindow and cast events there.
-
@p3c0
Could you please show me the proper way of doing this? So far I have added the method in my .h class:void resizeEvent(QResizeEvent * /* event */);
And in .cpp:
void MainWindow::resizeEvent(QResizeEvent * /* event */) { moveUndoView(); }
The moveUndoView() is :
void MainWindow::moveUndoView() { QPoint p = pos(); p += QPoint(width(), height()); p -= QPoint(undoView->width(), undoView->height()); undoView->move(p); }
I am getting segmentation fault when running this code. Any hints? The segfault occurs at line:
p -= QPoint(undoView->width(), undoView->height());For some reason I cannot acces undoView Object from this scope.
-
@Bremenpl With
cast an event
what do you mean by it ? What are you trying to achieve ? Can you post more details ? Looking at code it seems you are trying to move some widget.
Also please use ``` (3 backticks) for posting code blocks. -
@Bremenpl If you want to some it in accordance with the MainWindow that you can get width and height from
QResizeEvent
and move theQUndoView
. Something likevoid MainWindow::resizeEvent(QResizeEvent *e) { undoView->move(e->size().width(),undoView->y()); }
This will move
undoView
onx
axis as mainwindow resize. Add some more calculation as per your requirement. -
@p3c0
Theres an initialisation of the pointer in the class header:QUndoView *undoView;
Then In the mainwindow constructor I am running:
undoStack = new QUndoStack(this); undoView = new QUndoView(undoStack); undoView->setWindowTitle(tr("Command List")); undoView->setWindowFlags(Qt::WindowStaysOnTopHint); undoView->setAttribute(Qt::WA_QuitOnClose, false); undoView->show(); moveUndoView(); // PLEASE NOTE THAT THIS WORKS IN HERE, NO SEGFAULTS
-
@Bremenpl Does it crash when you attempt to resize manually or as soon as you execute the application ? Because resize event will be fired at application startup too. Make sure
undoView
was initialized prior to this first resize event. -
@p3c0
You are right, that is the problem. The thing is, that I cant really create this object before i execute this->show() (MainWindow), because the program crashes as well.Edit: undoStack and undoView had to be both declared before ui is build, I have forgot about that one. Now everything works, thank you a lot for help!