Make Qt menu appear programatically

时间:2018-02-05 12:56:00

标签: python c++ qt pyqt

I have a QMenu in a QMenuBar.

I can make the QMenu appear via QMenu.show() QMenu.exec() and QMenu.showTearOffMenu(), but these show the menu at the top-left of the screen, at a prespecified position, or under the mouse. I want the menu to appear in its usual position (under the QMenuBar). Is this possible (in any Qt language)?

2 个答案:

答案 0 :(得分:1)

你可以简单地使用

$fa-font-path: "font-awesome/fonts" !default;

@import 'font-awesome/scss/font-awesome';

其中self将对应于QMainWindow

参考 setMenuBar

  

将主窗口的菜单栏设置为menuBar。

AttributeTypecastBehavior

答案 1 :(得分:0)

在Qt中,您可以使用菜单栏的位置,然后打开该位置的菜单:

$(function() {
  var chartChartColumnRangeRate;
  var chartChartHistorian;

  $(document).ready(function() {
    function unzoom() {
      chartChartColumnRangeRate.options.chart.isZoomed = false;
      chartChartColumnRangeRate.yAxis[0].setExtremes(null, null);
      chartChartColumnRangeRate.yAxis[0].isDirty = true;
      chartChartHistorian.options.chart.isZoomed = false;
      chartChartHistorian.xAxis[0].setExtremes(null, null);
      chartChartHistorian.xAxis[0].isDirty = true;
    }

    chartChartColumnRangeRate = Highcharts.chart('ChartColumnRangeRate', {
      chart: {
        type: 'columnrange',
        height: 120,
        inverted: true,
        zoomType: 'y'
      },
      title: {
        text: null
      },
      xAxis: {
        lineColor: 'transparent',
        labels: {
          enabled: false
        },
        tickLength: 0
      },
      yAxis: {
        gridLineWidth: 0,
        max: 1517374800000,
        min: 1517288400000,
        lineColor: 'transparent',
        startOnTick: false,
        endOnTick: false,
        labels: {
          enabled: true
        },
        title: {
          text: null,
        },
        type: 'datetime',
        events: {
          afterSetExtremes: function() {
            if (!this.chart.options.chart.isZoomed) {
              var min = this.chart.yAxis[0].min;
              var max = this.chart.yAxis[0].max;

              chartChartColumnRangeRate.yAxis[0].isDirty = true;
              chartChartHistorian.xAxis[0].isDirty = true;
              chartChartHistorian.xAxis[0].setExtremes(min, max, true);
              chartChartHistorian.options.chart.isZoomed = false;
            }
          }
        }
      },
      plotOptions: {
        columnrange: {
          dataLabels: {
            enabled: false
          },
          animation: true
        },
        series: {
          cursor: 'pointer',
          borderWidth: 0,
          point: {
            events: {
              click: function(e) {
                if (e.point.series.options.clickable)
                  location.href = '../../events/eventview?EventID=' + this.options.id;
              }
            }
          }
        }
      },
      tooltip: {
        formatter: function() {
          var tooltip = '<b>' + this.series.name + '</b>';
          if (this.series.name != 'Running' && this.series.name != 'Future') {
            tooltip += '<br/>' + Highcharts.dateFormat('%b %d %Y %H:%M', this.point.low) + ' - ' + Highcharts.dateFormat('%b %d %Y %H:%M', this.point.high);
          }
          return tooltip;
        }
      },
      legend: {
        enabled: true,
        useHTML: true,
        labelFormatter: function() {
          return this.userOptions.id
        }
      },
      exporting: {
        enabled: false
      },
      credits: {
        enabled: false
      },
      series: [{
        name: 'Packing No Product',
        id: 'Performance Loss',
        color: '#fde54a',
        clickable: true,
        groupPadding: 0.5,
        pointWidth: 120,
        zIndex: 2,
        data: [{
          "id": 55923,
          "low": 1517326575000,
          "high": 1517326614000
        }]
      }, {
        name: 'Packing No Product',
        id: 'Availability Loss',
        color: '#d9534f',
        clickable: true,
        groupPadding: 0.5,
        pointWidth: 120,
        zIndex: 2,
        data: [{
          "id": 55902,
          "low": 1517325959000,
          "high": 1517326157000
        }]
      }, {
        name: 'Packing No Product',
        id: 'Performance Loss',
        color: '#fde54a',
        clickable: true,
        groupPadding: 0.5,
        pointWidth: 120,
        zIndex: 2,
        linkedTo: 'Performance Loss',
        data: [{
          "id": 55888,
          "low": 1517323956000,
          "high": 1517323968000
        }]
      }, {
        name: 'Packing No Product',
        id: 'Performance Loss',
        color: '#fde54a',
        clickable: true,
        groupPadding: 0.5,
        pointWidth: 120,
        zIndex: 2,
        linkedTo: 'Performance Loss',
        data: [{
          "id": 55859,
          "low": 1517322584000,
          "high": 1517322603000
        }]
      }, {
        name: 'Packing No Product',
        id: 'Availability Loss',
        color: '#d9534f',
        clickable: true,
        groupPadding: 0.5,
        pointWidth: 120,
        zIndex: 2,
        linkedTo: 'Availability Loss',
        data: [{
          "id": 55844,
          "low": 1517322306000,
          "high": 1517322513000
        }]
      }, {
        name: 'Packing No Product',
        id: 'Performance Loss',
        color: '#fde54a',
        clickable: true,
        groupPadding: 0.5,
        pointWidth: 120,
        zIndex: 2,
        linkedTo: 'Performance Loss',
        data: [{
          "id": 55834,
          "low": 1517322159000,
          "high": 1517322193000
        }]
      }, {
        name: 'Packing No Product',
        id: 'Availability Loss',
        color: '#d9534f',
        clickable: true,
        groupPadding: 0.5,
        pointWidth: 120,
        zIndex: 2,
        linkedTo: 'Availability Loss',
        data: [{
          "id": 55815,
          "low": 1517321389000,
          "high": 1517321863000
        }]
      }, {
        name: 'Packing No Product',
        id: 'Performance Loss',
        color: '#fde54a',
        clickable: true,
        groupPadding: 0.5,
        pointWidth: 120,
        zIndex: 2,
        linkedTo: 'Performance Loss',
        data: [{
          "id": 55813,
          "low": 1517321352000,
          "high": 1517321359000
        }]
      }, {
        name: 'Packing Not In Use',
        id: 'Availability Loss',
        color: '#d9534f',
        clickable: true,
        groupPadding: 0.5,
        pointWidth: 120,
        zIndex: 2,
        linkedTo: 'Availability Loss',
        data: [{
          "id": 55803,
          "low": 1517320594000,
          "high": 1517321352000
        }]
      }, {
        name: 'Running',
        id: 'Running',
        color: '#6cc14c',
        clickable: false,
        groupPadding: 0.5,
        pointWidth: 120,
        zIndex: 0,
        data: [{
          low: 1517288400000,
          high: 1517374800000
        }]
      }]
    });

    chartChartHistorian = Highcharts.chart('ChartHistorian', {
      chart: {
        type: 'line',
        height: 400,
        zoomType: 'x'
      },
      title: {
        text: null
      },
      xAxis: {
        type: 'datetime',
        title: {
          text: null
        },
        max: 1517374800000,
        min: 1517288400000,
        events: {
          afterSetExtremes: function() {
            if (!this.chart.options.chart.isZoomed) {
              var min = this.chart.xAxis[0].min;
              var max = this.chart.xAxis[0].max;

              chartChartHistorian.xAxis[0].isDirty = true;
              chartChartColumnRangeRate.yAxis[0].isDirty = true;
              chartChartColumnRangeRate.yAxis[0].setExtremes(min, max, true);
              chartChartColumnRangeRate.options.chart.isZoomed = false;
            }
          }
        }
      },
      yAxis: {
        title: {
          text: null
        },
        min: 0
      },
      tooltip: {
        shared: true
      },
      legend: {
        enabled: true
      },
      exporting: {
        enabled: false
      },
      credits: {
        enabled: false
      },
      series: [{
        "name": "Rate",
        "tooltip": {
          "valueSuffix": " Products/min"
        },
        "turboThreshold": 0,
        "data": [{
          "x": 1517288400127,
          "y": 700.0
        }, {
          "x": 1517288415127,
          "y": 700.0
        }, {
          "x": 1517288430127,
          "y": 0.0
        }, {
          "x": 1517288445127,
          "y": 0.0
        }, {
          "x": 1517288460127,
          "y": 0.0
        }, {
          "x": 1517288475127,
          "y": 0.0
        }, {
          "x": 1517288490127,
          "y": 100.0
        }, {
          "x": 1517288505127,
          "y": 100.0
        }, {
          "x": 1517288520127,
          "y": 100.0
        }, {
          "x": 1517288535127,
          "y": 100.0
        }, {
          "x": 1517288550127,
          "y": 1303.0
        }, {
          "x": 1517288565127,
          "y": 1303.0
        }, {
          "x": 1517288580127,
          "y": 1303.0
        }, {
          "x": 1517288595127,
          "y": 1303.0
        }, {
          "x": 1517288610127,
          "y": 900.0
        }, {
          "x": 1517288625127,
          "y": 900.0
        }, {
          "x": 1517288640127,
          "y": 900.0
        }, {
          "x": 1517288655127,
          "y": 900.0
        }, {
          "x": 1517288670127,
          "y": 1300.0
        }, {
          "x": 1517288685127,
          "y": 1300.0
        }, {
          "x": 1517288700127,
          "y": 1300.0
        }, {
          "x": 1517288715127,
          "y": 1300.0
        }, {
          "x": 1517288730127,
          "y": 1550.0
        }, {
          "x": 1517288745127,
          "y": 1550.0
        }, {
          "x": 1517288760127,
          "y": 1550.0
        }, {
          "x": 1517288775127,
          "y": 1550.0
        }, {
          "x": 1517288790127,
          "y": 1400.0
        }, {
          "x": 1517288805127,
          "y": 1400.0
        }, {
          "x": 1517288820127,
          "y": 1400.0
        }, {
          "x": 1517288835127,
          "y": 1400.0
        }, {
          "x": 1517288850127,
          "y": 1500.0
        }, {
          "x": 1517288865127,
          "y": 1500.0
        }, {
          "x": 1517288880127,
          "y": 1500.0
        }, {
          "x": 1517288895127,
          "y": 1500.0
        }, {
          "x": 1517288910127,
          "y": 1100.0
        }, {
          "x": 1517288925127,
          "y": 1100.0
        }, {
          "x": 1517288940127,
          "y": 1100.0
        }, {
          "x": 1517288955127,
          "y": 1100.0
        }, {
          "x": 1517288970127,
          "y": 651.0
        }, {
          "x": 1517288985127,
          "y": 651.0
        }, {
          "x": 1517289000127,
          "y": 651.0
        }, {
          "x": 1517289015127,
          "y": 651.0
        }, {
          "x": 1517289030127,
          "y": 750.0
        }, {
          "x": 1517289045127,
          "y": 750.0
        }, {
          "x": 1517289060127,
          "y": 750.0
        }, {
          "x": 1517289075127,
          "y": 750.0
        }, {
          "x": 1517289090127,
          "y": 1050.0
        }, {
          "x": 1517289105127,
          "y": 1050.0
        }, {
          "x": 1517289120127,
          "y": 1050.0
        }, {
          "x": 1517289135127,
          "y": 1050.0
        }, {
          "x": 1517289150127,
          "y": 1450.0
        }, {
          "x": 1517326920127,
          "y": 600.0
        }, {
          "x": 1517326935127,
          "y": 600.0
        }, {
          "x": 1517326950127,
          "y": 600.0
        }]
      }]
    });
  });
});