Results 1 to 3 of 3

Thread: Enable/Disable Zoom with a checkable action

  1. #1
    Join Date
    Oct 2008
    Location
    Aachen
    Posts
    20
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Unhappy Enable/Disable Zoom with a checkable action

    Hi all,

    i need some help regarding the following issue. I have a QwtPlot with some functionalities on right mouse click.

    Qt Code:
    1. void Sys_Plot_Wid::contextMenuEvent(QContextMenuEvent *event)
    2. {
    3. QMenu contextMenu(this);
    4. contextMenu.addAction(printAct);
    5. contextMenu.addAction(printPDFAct);
    6. contextMenu.addAction(saveasAct);
    7. contextMenu.addAction(zoomAct);
    8. contextMenu.addAction(showGridAct);
    9. contextMenu.exec(event->globalPos());
    10. }
    To copy to clipboard, switch view to plain text mode 

    I want to be able to enable or disable my zoomer with a checkable action. I can enable the zoom by clicking my action but as i uncheck the action, the zoomer is still enabled. Can someone tell me what am i doing wrong?

    Action is declared in my ctor like:
    Qt Code:
    1. this->zoomAct->setCheckable(true);
    2. this->zoomAct->setChecked(false);
    To copy to clipboard, switch view to plain text mode 

    I connect the action with:
    Qt Code:
    1. QObject::connect(this->zoomAct, SIGNAL(toggled(bool)), this, SLOT(enableZoomMode(bool)));
    To copy to clipboard, switch view to plain text mode 

    And the enableZoomMode function looks like:
    Qt Code:
    1. void Sys_Plot_Wid::enableZoomMode(bool on)
    2. {
    3. QwtPlotMagnifier *plotMagnifier = new QwtPlotMagnifier(this->canvas());
    4. QwtPlotPanner *plotPanner = new QwtPlotPanner(this->canvas());
    5. QwtPlotZoomer *plotZoomer = new QwtPlotZoomer(this->canvas(), true);
    6. QwtPlotPicker *picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPicker::PointSelection | QwtPicker::DragSelection,
    7. QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, this->canvas());
    8.  
    9. plotMagnifier->setMouseButton(Qt::MidButton);
    10. plotMagnifier->setEnabled(on);
    11. plotPanner->setMouseButton(Qt::LeftButton);
    12. plotPanner->setEnabled(on);
    13. plotZoomer->setMousePattern(0, Qt::LeftButton, Qt::ControlModifier);
    14. plotZoomer->setMousePattern(1, Qt::MidButton);
    15. plotZoomer->setMousePattern(2, Qt::NoButton);
    16. plotZoomer->setEnabled(on);
    17. picker->setRubberBandPen(QColor(Qt::darkCyan));
    18. picker->setRubberBand(QwtPicker::CrossRubberBand);
    19. picker->setEnabled(!on);
    20.  
    21. this->replot();
    22. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for your replies.

  2. #2
    Join Date
    May 2009
    Posts
    20
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Enable/Disable Zoom with a checkable action

    You shouldn't be creating new zoomers, pickers, etc. every time you toggle. Create them once and the slot should only enable and disable them.

  3. The following user says thank you to Ban-chan for this useful post:

    yannwilfried (2nd December 2009)

  4. #3
    Join Date
    Oct 2008
    Location
    Aachen
    Posts
    20
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Enable/Disable Zoom with a checkable action

    Basic C++ Knowledges were required . Thx a lot.

Similar Threads

  1. Checkable Action Icon
    By zgulser in forum Qt Tools
    Replies: 8
    Last Post: 15th January 2009, 13:13

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.