<i id='Avq8O'><tr id='Avq8O'><dt id='Avq8O'><q id='Avq8O'><span id='Avq8O'><b id='Avq8O'><form id='Avq8O'><ins id='Avq8O'></ins><ul id='Avq8O'></ul><sub id='Avq8O'></sub></form><legend id='Avq8O'></legend><bdo id='Avq8O'><pre id='Avq8O'><center id='Avq8O'></center></pre></bdo></b><th id='Avq8O'></th></span></q></dt></tr></i><div id='Avq8O'><tfoot id='Avq8O'></tfoot><dl id='Avq8O'><fieldset id='Avq8O'></fieldset></dl></div>

      • <bdo id='Avq8O'></bdo><ul id='Avq8O'></ul>
      1. <legend id='Avq8O'><style id='Avq8O'><dir id='Avq8O'><q id='Avq8O'></q></dir></style></legend>
        <tfoot id='Avq8O'></tfoot>
      2. <small id='Avq8O'></small><noframes id='Avq8O'>

        如何在右侧 cilck 上的 Qdoublespinbox 上向 QtCore.Qt.

        时间:2023-08-04

          <small id='rMrQq'></small><noframes id='rMrQq'>

            <bdo id='rMrQq'></bdo><ul id='rMrQq'></ul>

              • <tfoot id='rMrQq'></tfoot>
                <legend id='rMrQq'><style id='rMrQq'><dir id='rMrQq'><q id='rMrQq'></q></dir></style></legend>

                • <i id='rMrQq'><tr id='rMrQq'><dt id='rMrQq'><q id='rMrQq'><span id='rMrQq'><b id='rMrQq'><form id='rMrQq'><ins id='rMrQq'></ins><ul id='rMrQq'></ul><sub id='rMrQq'></sub></form><legend id='rMrQq'></legend><bdo id='rMrQq'><pre id='rMrQq'><center id='rMrQq'></center></pre></bdo></b><th id='rMrQq'></th></span></q></dt></tr></i><div id='rMrQq'><tfoot id='rMrQq'></tfoot><dl id='rMrQq'><fieldset id='rMrQq'></fieldset></dl></div>

                    <tbody id='rMrQq'></tbody>
                • 本文介绍了如何在右侧 cilck 上的 Qdoublespinbox 上向 QtCore.Qt.DefaultContextMenu 添加操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我使用 Qt Designer 开发了一个相当复杂的 GUI 工具.

                  有关该工具的更多详细信息,请参阅:

                  然后点击添加按钮,然后点击提升按钮.

                  对于另一个QDoubleSpinBox,右键单击并选择DoubleSpinBox选项所在的新Promote To选项.

                  <小时>

                  您可以在这里找到一个示例

                  I have developed a fairly complex GUI tool using the Qt Designer.

                  For more details about the tool see: https://github.com/3fon3fonov/trifon

                  I have defined many QDoubleSpinBox entries and by default the Qt Designer sets their right-click menu policy to:

                  setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
                  

                  Now I want to add few more actions to this menu, but I simply cannot understand how this works! There is nothing in the Qt Designer which will allow me to make a "CustomContextMenu". I understand that for this I may need some coding (with which I will need help, and thus I am asking for help here), but I also need to make it globally for all SpinBox-es.

                  Sorry for not posting the code since it is fairly large for this form. If interested, please look at the github under "gui.py". However, there and in the .ui file there is no sign of any possibility to control the contextmenu policy for these buttons. Instead I am posting an image of the tool (sorry for the bad image but PrtSc does not seem to work when the right button in clicked and the menu is displayed)

                  see GUI image here

                  解决方案

                  As we want to add a QAction to the default context menu we first overwrite the contextMenuEvent event and use a QTimer to call a function that filters the toplevels and get the QMenu that is displayed and there we add the QAction:

                  doublespinbox.py

                  from PyQt5 import QtCore, QtWidgets
                  
                  class DoubleSpinBox(QtWidgets.QDoubleSpinBox):
                      minimize_signal = QtCore.pyqtSignal()
                  
                      def __init__(self, *args, **kwargs):
                          super(DoubleSpinBox, self).__init__(*args, **kwargs)
                          self.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
                  
                      def contextMenuEvent(self, event):
                          QtCore.QTimer.singleShot(0, self.add_actions)
                          super(DoubleSpinBox, self).contextMenuEvent(event)
                  
                      @QtCore.pyqtSlot()
                      def add_actions(self):
                          for w in QtWidgets.QApplication.topLevelWidgets():
                              if isinstance(w, QtWidgets.QMenu) and w.objectName() == "qt_edit_menu":
                                  w.addSeparator()
                                  minimize_action = w.addAction("minimize this parameter")
                                  minimize_action.triggered.connect(self.minimize_signal)
                  
                  if __name__ == '__main__':
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      w = DoubleSpinBox()
                      w.show()
                      sys.exit(app.exec_())
                  


                  To use DoubleSpinBox in Qt Designer, first place doublespinbox.py next to your .ui:

                  ├── ..
                  ├── rvmod_gui.ui
                  ├── doublespinbox.py   
                  ├── ...
                  

                  then you must promote the widget to do so right click on the QDoubleSpinBox and select the option "Promote to ..." by adding the following to the dialog:

                  Then click on the Add button and then the Promote button.

                  For the other QDoubleSpinBox, right click and select the new Promote To option where the DoubleSpinBox option is.


                  You can find an example here

                  这篇关于如何在右侧 cilck 上的 Qdoublespinbox 上向 QtCore.Qt.DefaultContextMenu 添加操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:通过信号调用函数将默认键控参数更改为“Fals 下一篇:装饰器添加了一个意想不到的参数

                  相关文章

                  最新文章

                    <legend id='ojKQD'><style id='ojKQD'><dir id='ojKQD'><q id='ojKQD'></q></dir></style></legend>

                    <small id='ojKQD'></small><noframes id='ojKQD'>

                    • <bdo id='ojKQD'></bdo><ul id='ojKQD'></ul>

                      <tfoot id='ojKQD'></tfoot>
                    1. <i id='ojKQD'><tr id='ojKQD'><dt id='ojKQD'><q id='ojKQD'><span id='ojKQD'><b id='ojKQD'><form id='ojKQD'><ins id='ojKQD'></ins><ul id='ojKQD'></ul><sub id='ojKQD'></sub></form><legend id='ojKQD'></legend><bdo id='ojKQD'><pre id='ojKQD'><center id='ojKQD'></center></pre></bdo></b><th id='ojKQD'></th></span></q></dt></tr></i><div id='ojKQD'><tfoot id='ojKQD'></tfoot><dl id='ojKQD'><fieldset id='ojKQD'></fieldset></dl></div>