View Full Version : Qwt zoom vs. Qt move

12th November 2007, 00:54
I have a QMainWindow application A which opens another QMainWindow application B. The second application (B) has a widget that displays a QwtPlot with a QwtPlotZoomer.
I can run application B independently or open it as a window through application A.

When I run B independently, it works well: I can zoom in and out of the plot.
When I run A and create B as a child, I get two signals - 1. the original zoom 2. moving of the window inside the central widget.

I'm not interested in moving the window when I'm in the QwtPlot widget (only zooming).
How can I disable the second signal for only that widget? (As I still want to be able to move the window when outside the plot widget)
I didn't connect the move signal so I assume it's done by default?

12th November 2007, 07:09
Hard to understand, what you mean by "signal", but obviously it is not: http://doc.trolltech.com/4.3/signalsandslots.html.
Do you mean, that in situation B your plot widget gets moved around, when you drag the left mouse button on the plot canvas ?


12th November 2007, 21:19
I'll try to explain again:
I open a window in the central area of my QMainWindow application. This window contains a widget that displays a plot. When I try to zoom by dragging the left mouse button on the plot canvas, the whole window (not just the plot widget) moves as well (inside the QMainWindow central area).
So the zoom functionality works fine but in addition the window moves (which makes it difficult to zoom).

13th November 2007, 07:48
I open a window in the central area of my QMainWindow application.
What do you mean by open - guess it is not QMainWindow::setCentralWidget ?
Sounds a bit like you are using QMdiArea/QMdiSubWindow.


13th November 2007, 21:47
I have:

class MyMainWindow : public QMainWindow

MyMainWindow::MyMainWindow() : QMainWindow(0,0)
workspace_ = new QWorkspace();

void MyMainWindow::createChild()
child = new MyTool();

class MyTool : public QMainWindow

MyTool::MyTool(QWidget * parent) : QMainWindow(parent,0)
scrollArea_ = new QScrollArea;
scrollArea_->setWidgetResizable ( true );
scrollArea_->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
scrollArea_->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
scrollAreaGridLayout_ = new QGridLayout(scrollArea_);
scrollAreaWidget_ = new QWidget();
scrollAreaGridLayout_->addWidget(scrollAreaWidget_, 0, 1, 1, 1);
tabWidget_ = new QTabWidget();
scrollAreaGridLayout2_ = new QGridLayout(scrollAreaWidget_);
scrollAreaGridLayout2_->addWidget(tabWidget_, 0, 1, 1, 1);
The tabWidget_ will eventually display Profile - a class that contains a plot:

class Profile : public QWidget

Profile::Profile(QWidget * parent) : QWidget(parent)
graphicDisplay = new ProfileGraphicDisplay(this);

class ProfileGraphicDisplay : public QwtPlot

ProfileGraphicDisplay ::ProfileGraphicDisplay (QWidget *parent) : QwtPlot(parent)
canvas1_ = canvas();
canvas1_->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicato r);
canvas1Picker_ = new QwtPlotPicker( canvas1_ );
canvas1Picker_->setSelectionFlags( QwtPicker::PointSelection | QwtPicker::DragSelection );
canvas1Picker_->setTrackerMode( QwtPicker::AlwaysOff );
connect( canvas1Picker_, SIGNAL( selected( const QwtDoublePoint & ) ), this, SLOT( pointSelected( const QwtDoublePoint & ) ) );
canvas1Zoomer_ = new QwtPlotZoomer( QwtPlot::xBottom, QwtPlot::yLeft, canvas1_ );
canvas1Zoomer_->setSelectionFlags( QwtPicker::DragSelection );
curve1_ = new QwtPlotCurve();
curve1_->setData( xProfile_, yProfile_ );

So, When I use canvas1Zoomer_ to zoom in the ProfileGraphicDisplay area, MyTool window moves inside workspace_.

14th November 2007, 07:21
AFAIR, this can be fixed by setting the Qt::WA_NoMousePropagation flag. What happens, when you add the following line to MyMainWindow::createChild:

child->setAttribute(Qt::WA_NoMousePropagation, false);


14th November 2007, 21:09
child->setAttribute(Qt::WA_NoMousePropagation, true);

That worked.
Thank you Uwe.