Issue
i have built an application in python using PySide6 & Qt designer where i added a matplotlibWidget to window main_plot_container
and NavigationToolbar2QT to a tb_frame
that sits on top of main_plot_container
. i wanted to customize toolbar by moving it out of the plot area and give it custom icons. all good - this is done and works fine. the only issue I'm having is when someone clicks on either pan or zoom button/icon, they not visualally indicate that they are active (DO NOT highliht background when active). this is driving user confusion, tryint to click other buttons not knowing that these buttons are active already. below code snipet on how this is coded.
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as Canvas
class MatplotlibWidget(QWidget):
def __init__(self, parent=None):
super(MatplotlibWidget, self).__init__(parent)
self.toolbar = NavigationToolbar(self.canvas, self)
self.figure, self.subplot_dict = plt.subplots()
self.canvas = Canvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
self.layout.addWidget(self.canvas)
....
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.mpl_widget = MatplotlibWidget(self.ui.main_plot_container)
self.ui.main_plot_container.layout().addWidget(self.mpl_widget)
self.ui.tb_frame.layout().addWidget(self.mpl_widget.toolbar)
icons_buttons = {
"Home": QtGui.QIcon(":/icons/icons/home.svg"),
"Pan": QtGui.QIcon(":/icons/icons/move.svg"),
"Zoom": QtGui.QIcon(":/icons/icons/zoom-in.svg"),
"Back": QtGui.QIcon(":/icons/icons/corner-up-left.svg"),
"Forward": QtGui.QIcon(":/icons/icons/corner-up-right.svg"),
"Save": QtGui.QIcon(":/icons/icons/save.svg"),
"Subplots": QtGui.QIcon(":/icons/icons/sliders.svg"),
"Customize": QtGui.QIcon(":/icons/icons/trending-up.svg")}
for action in self.toolbar.actions():
if action.text() in icons_buttons:
action.setIcon(icons_buttons.get(action.text(), QtGui.QIcon()))
....
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
python v3.11
matplotlib v3.7.4
PySide6 v6.5.1
Qt v6.5.1
Solution
i was able to get to the root cause of this issue. Qt QPushButton & QToolButton styleSheet formatting for other non-navigationToolBar button somehow caused this weird behavior.
QToolButton, QPushButton{border: nine;}
i solved it by removing QToolButtons from the formatting.
QPushButton{border: nine;}
Answered By - Hannibal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.