On Tue, 4 Oct 2011 10:09:57 +0200
Jens Nie <[email protected]> wrote:
> Hi Nils.
>
> The Qt based Navigation toolbar is just a Qt Widget with
>a proper layout already set. So you should be able to add
>any Qt widget to the toolbar using its addWidget method.
> I was able to add a simple line edit (without any use)
>like so:
>
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_qt4agg import
>FigureCanvasQTAgg as FigureCanvas
> from matplotlib.backends.backend_qt4agg import
>NavigationToolbar2QT as NavigationToolbar2
>
> class ViewWidget(QMainWindow):
> def __init__(self):
> QMainWindow.__init__(self)
>
> # create a simple main widget to keep the figure
> self.mainWidget = QWidget()
> self.setCentralWidget(self.mainWidget)
>
> layout = QVBoxLayout()
> self.mainWidget.setLayout(layout)
>
> # create a figure
> self.figure_canvas = FigureCanvas(Figure())
> layout.addWidget(self.figure_canvas, 10)
>
> # and the axes for the figure
> self.axes =
>self.figure_canvas.figure.add_subplot(111)
>
> # add a navigation toolbar
> self.navigation_toolbar =
>NavigationToolbar2(self.figure_canvas, self)
> layout.addWidget(self.navigation_toolbar, 0)
>
> # create a simple widget to extend the navigation
>toolbar
> anotherWidget=QLineEdit()
> # add the new widget to the existing navigation
>toolbar
> self.navigation_toolbar.addWidget(anotherWidget)
>
> if __name__=="__main__":
> app=QApplication(sys.argv)
> mw=ViewWidget()
> mw.show()
> sys.exit(app.exec_())
>
> Hope that helps ...
>
> Best regards
>
> Jens
>
Hi Jens,
Thank you very much for your response.
Hence I have tried
import sys
import numpy as np
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import
FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import
NavigationToolbar2QT as NavigationToolbar2
class ViewWidget(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
# create a simple main widget to keep the figure
self.mainWidget = QWidget()
self.setCentralWidget(self.mainWidget)
layout = QVBoxLayout()
self.mainWidget.setLayout(layout)
# create a figure
self.figure_canvas = FigureCanvas(Figure())
layout.addWidget(self.figure_canvas, 10)
# and the axes for the figure
self.axes =
self.figure_canvas.figure.add_subplot(111)
x = np.linspace(0.,2*np.pi,100)
self.axes.plot(x,np.sin(x))
# add a navigation toolbar
self.navigation_toolbar =
NavigationToolbar2(self.figure_canvas, self)
layout.addWidget(self.navigation_toolbar, 0)
# create a simple widget to extend the navigation
toolbar
# anotherWidget=QLineEdit()
printer = QPrinter()
anotherWidget= QPrintDialog(printer,self)
# add the new widget to the existing navigation
toolbar
self.navigation_toolbar.addWidget(anotherWidget)
if __name__=="__main__":
app=QApplication(sys.argv)
mw=ViewWidget()
mw.show()
sys.exit(app.exec_())
How do I connect the plot with the printer ?
How can I replace the printer dialog by a small icon ?
I found the lines
a = self.addAction(self._icon('filesave.svg'),
'Save',
self.save_figure)
in backend_qt4.py
Nils
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users