02-02-2014, 06:15 PM | #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? |
02-02-2014, 09:23 PM | #2 |
creator of calibre
Posts: 43,866
Karma: 22666666
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. |
Advert | |
|
02-02-2014, 10:28 PM | #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 10:30 PM. Reason: formating |
|
02-02-2014, 10:48 PM | #4 |
creator of calibre
Posts: 43,866
Karma: 22666666
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.
|
02-02-2014, 11:09 PM | #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) |
|
Advert | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problem with p toolbar button | JimmyG | Sigil | 9 | 02-14-2013 04:26 PM |
Eject button on toolbar? | alliani | Calibre | 9 | 12-08-2012 07:31 AM |
Wikipedia button/plugin for Calibre? | ChrisKaos | Calibre | 2 | 04-20-2012 04:53 PM |
Can I hold a reference to .model() and .db in a plugin? | kiwidude | Development | 11 | 02-18-2011 06:52 PM |
Interface - Button size in toolbar suggestion | jbpilote | Calibre | 1 | 01-31-2010 10:27 AM |