|
|
#1 |
|
Member
![]() Posts: 15
Karma: 10
Join Date: Feb 2014
Device: none
|
reference to the plugin's toolbar button
i would like to make plugin with drop-down menu (self.popup_type = QToolButton.InstantPopup) and instead of textual (q)action i would like to add custom QWidget.
i have separated code which looks like this: Code:
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
layout = QtGui.QHBoxLayout(self)
self.button = QtGui.QToolButton(self)
self.button.setPopupMode(QtGui.QToolButton.InstantPopup)
self.button.setMenu(QtGui.QMenu(self.button))
self.textBox = QtGui.QTextBrowser(self)
action = QtGui.QWidgetAction(self.button)
action.setDefaultWidget(self.textBox)
self.button.menu().addAction(action)
layout.addWidget(self.button)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.resize(100, 60)
window.show()
sys.exit(app.exec_())
in calibre plugin development i tried things like: self.qaction.parentWidget() and few others (but rather would avoid showing it )no luck. any idea how to do that? |
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,626
Karma: 28549046
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
See setup_tool_button() in gui2/bars.py
Though I'm not clear why you need a reference to the button. Simply add your QWidgetAction to the qactions menu as you would normally. |
|
|
|
|
|
#3 | |
|
Member
![]() Posts: 15
Karma: 10
Join Date: Feb 2014
Device: none
|
Quote:
when i do this in InterfaceAction.genesis (having action_add_menu = True): Code:
self.qaction.menu().addAction(QWidgetAction().setDefaultWidget(d)) Last edited by kabirmaar; 02-02-2014 at 11:30 PM. Reason: formating |
|
|
|
|
|
|
#4 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,626
Karma: 28549046
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Set the menu as the parent. And keep a python reference to the widget action to prevent it from being garbage collected.
|
|
|
|
|
|
#5 | |
|
Member
![]() Posts: 15
Karma: 10
Join Date: Feb 2014
Device: none
|
Quote:
had to add QMenu(self.gui) to qaction and keep a python reference to the widget action... Code:
d = MyPlugin(self.gui, self.qaction.icon(), do_user_config, self.qaction) m = QMenu(self.gui) self.qaction.setMenu(m) a = QWidgetAction(m) a.setDefaultWidget(d) m.addAction(a) |
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with p toolbar button | JimmyG | Sigil | 9 | 02-14-2013 05:26 PM |
| Eject button on toolbar? | alliani | Calibre | 9 | 12-08-2012 08:31 AM |
| Wikipedia button/plugin for Calibre? | ChrisKaos | Calibre | 2 | 04-20-2012 05:53 PM |
| Can I hold a reference to .model() and .db in a plugin? | kiwidude | Development | 11 | 02-18-2011 07:52 PM |
| Interface - Button size in toolbar suggestion | jbpilote | Calibre | 1 | 01-31-2010 11:27 AM |