<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Mouse and QMenuBar]]></title><description><![CDATA[<p dir="auto">Hello, I would like to know if there is any to disable the mouse events that occur when clicking on one of the menu options. As you can see in the image I have a white square that highlights the options of my menubar but when this happens if I move the mouse and place it on top of some option of my menubar and click to open the submenu as seen in the image. I would like this not to happen.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/511667b6-4aa5-449f-8aab-525a8428c29a.png" alt="Captura de pantalla (32).png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/topic/126921/mouse-and-qmenubar</link><generator>RSS for Node</generator><lastBuildDate>Sun, 14 Jun 2026 09:35:38 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/126921.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 23 May 2021 22:49:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Mouse and QMenuBar on Thu, 27 May 2021 05:13:28 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
it seems to me that in</p>
<pre><code>int MainWindow::botondirecto()
{
    main = new MainWindow(); &lt;&lt;&lt; make new window . its not the old one from botonbarrido()
    ui-&gt;menubar-&gt;removeEventFilter(main); &lt;&lt;&lt; remove the filter but did we ever put one On as main seems new to me
</code></pre>
<p dir="auto">So did i drink from the night pot or<br />
did you mean to use removeEventFilter on the "main" we created in botonbarrido() ?</p>
<p dir="auto">Also do notice if you are using my code for the filter, then you can<br />
call<br />
SweepModeToggle(true) to have it filter and SweepModeToggle(false) to allow all.<br />
So you dont have to go and install and remove it.</p>
]]></description><link>https://forum.qt.io/post/661822</link><guid isPermaLink="true">https://forum.qt.io/post/661822</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 27 May 2021 05:13:28 GMT</pubDate></item><item><title><![CDATA[Reply to Mouse and QMenuBar on Wed, 26 May 2021 22:36:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
I have two buttons in the Sweep mode action, one of them activates the sweep mode where I install the filter so that the options are not displayed, that works well for me as you can see in the gif.</p>
<p dir="auto">But when I click Direct mode where I uninstall the filter but it doesn't work for me and the menus are still blocked.</p>
<pre><code>void MainWindow::on_actionModo_Barrido_2_triggered()
{

    modoBarrido = 0;
    topFiller = new QWidget;
    QVBoxLayout *box =  new QVBoxLayout;
    QPushButton *mododirecto = new QPushButton(tr("ModoDirecto"));
    QPushButton *modobarrido = new QPushButton(tr("ModoBarrido"));
   // layout-&gt;setContentsMargins(0, 40, 40, 40);
    box-&gt;addWidget(mododirecto);
    box-&gt;addWidget(modobarrido);

    topFiller-&gt;setLayout(box);
    topFiller-&gt;setGeometry(500,200,400,400);

    topFiller-&gt;setStyleSheet("background-color:rgb(23, 255, 240)");
    topFiller-&gt;show();

    connect(mododirecto,SIGNAL(clicked()),this,SLOT(botondirecto()));
    connect(modobarrido,SIGNAL(clicked()),this,SLOT(botonbarrido()));

}
int MainWindow::botonbarrido()
{
    main = new MainWindow();
    modoBarrido=0;
    if(modoBarrido==0){

        timeoutMenuPrincipal();
        topFiller-&gt;close();
        ui-&gt;menubar-&gt;installEventFilter(main);

    }

    return modoBarrido;

}

int MainWindow::botondirecto()
{
    main = new MainWindow();
    ui-&gt;menubar-&gt;removeEventFilter(main);
    modoBarrido=1;
    if(modoBarrido==1){
        Highlight-&gt;~QRubberBand();
        timer.stop();
        timer2.stop();
        timer.disconnect(&amp;timer, SIGNAL(timeout()), this, SLOT(BarridoMenuPrincipal()));
        timer2.disconnect(&amp;timer2, SIGNAL(timeout()), this, SLOT(BarridoSubMenu()));
        topFiller-&gt;close();

    }
    return modoBarrido;
}
</code></pre>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/201572c9-aa95-4848-823b-443fe76e33f5.gif" alt="screen-capture-5-h76w3wgv-zej7-mfzsncag-3q6r_5OH1CBCl_QL3U.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/43d4c315-6153-4642-a91d-71ec93456859.gif" alt="screen-capture-5-h76w3wgv-zej7-mfzsncag-3q6r_751zF4Yu_MWFp.gif" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/661804</link><guid isPermaLink="true">https://forum.qt.io/post/661804</guid><dc:creator><![CDATA[Oumayma]]></dc:creator><pubDate>Wed, 26 May 2021 22:36:11 GMT</pubDate></item><item><title><![CDATA[Reply to Mouse and QMenuBar on Wed, 26 May 2021 15:21:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/oumayma">@<bdi>Oumayma</bdi></a></p>
<p dir="auto">Hi<br />
You can use<br />
<a href="https://doc.qt.io/qt-5/qwidget.html#grabMouse" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qwidget.html#grabMouse</a><br />
to have all events go to some widget, effectively making it impossible to click on anything else.<br />
However, it offers no control of what can is eaten. and if you fail to to ungrab as many times as you grab,<br />
it will still be grapped. Also docs says:<br />
"Warning: Bugs in mouse-grabbing applications very often lock the terminal. Use this function with extreme caution, and consider using the -nograb command line option while debugging."</p>
<p dir="auto">Not the best solution, imho.</p>
<p dir="auto">So another solution is to use an event filter.</p>
<pre><code>// the filter class
#include &lt;QEvent&gt;
#include &lt;QMouseEvent&gt;

class MouseEater : public QObject
{
    Q_OBJECT
    bool sweepmodeActive{0};
protected:
    bool eventFilter(QObject *obj, QEvent *event)
    {
        if (event-&gt;type() == QEvent::MouseButtonPress || event-&gt;type() ==  QEvent::MouseButtonDblClick) {
            QMouseEvent *mp = static_cast&lt;QMouseEvent *&gt;(event);
            qDebug() &lt;&lt; "MouseButtonPress detected" &lt;&lt; sweepmodeActive;
            if ( mp-&gt;button() == Qt::LeftButton  ) {
                return sweepmodeActive; // say we handled it (true)
            }
        }
        return QObject::eventFilter(obj, event);// normal forward
    }
public slots:
    void SweepModeToggle( bool status)
    {
        sweepmodeActive = status;
        qDebug() &lt;&lt; "sweepmode" &lt;&lt; status;
    }
};

// in main window 
 MouseEater *me = new MouseEater();
 connect(ui-&gt;pushButton, &amp;QPushButton::toggled, me, &amp;MouseEater::SweepModeToggle ); // to toogle sweep mode
 ui-&gt;menubar-&gt;installEventFilter(me); // put filter ont he menubar
</code></pre>
<p dir="auto">the result is this.</p>
<p dir="auto"><img src="https://i.postimg.cc/Hs6yyNcN/drop4.gif" alt="alt text" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/661729</link><guid isPermaLink="true">https://forum.qt.io/post/661729</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 26 May 2021 15:21:30 GMT</pubDate></item><item><title><![CDATA[Reply to Mouse and QMenuBar on Wed, 26 May 2021 14:07:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> Another idea that has occurred to me is to block the movement of the mouse, when it is in sweep mode put the mouse cursor in the middle of the screen and that it cannot move from there but I don't know if this is possible.</p>
]]></description><link>https://forum.qt.io/post/661709</link><guid isPermaLink="true">https://forum.qt.io/post/661709</guid><dc:creator><![CDATA[Oumayma]]></dc:creator><pubDate>Wed, 26 May 2021 14:07:16 GMT</pubDate></item><item><title><![CDATA[Reply to Mouse and QMenuBar on Tue, 25 May 2021 19:18:25 GMT]]></title><description><![CDATA[<p dir="auto">Then one possible way would be to have a transparent widget on top of your UI that would block the interaction when in your swipe mode.</p>
]]></description><link>https://forum.qt.io/post/661534</link><guid isPermaLink="true">https://forum.qt.io/post/661534</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 25 May 2021 19:18:25 GMT</pubDate></item><item><title><![CDATA[Reply to Mouse and QMenuBar on Mon, 24 May 2021 20:59:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> My application has two access modes: the conventional one with mouse and keyboard, and sweep mode where the menu options are highlighted with a QRubberband. For the second mode I use the preesmouseevent method so that the menus are displayed or an action is executed, that is why I want the conventional mouse events to not work when the user is in this mode.</p>
]]></description><link>https://forum.qt.io/post/661377</link><guid isPermaLink="true">https://forum.qt.io/post/661377</guid><dc:creator><![CDATA[Oumayma]]></dc:creator><pubDate>Mon, 24 May 2021 20:59:45 GMT</pubDate></item><item><title><![CDATA[Reply to Mouse and QMenuBar on Mon, 24 May 2021 20:15:11 GMT]]></title><description><![CDATA[<p dir="auto">Can you give more details so that we can devise a solution ?</p>
]]></description><link>https://forum.qt.io/post/661361</link><guid isPermaLink="true">https://forum.qt.io/post/661361</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 24 May 2021 20:15:11 GMT</pubDate></item><item><title><![CDATA[Reply to Mouse and QMenuBar on Mon, 24 May 2021 19:50:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> I had thought about that but the functionality that I have in the application does not help me to disable the menu.</p>
]]></description><link>https://forum.qt.io/post/661357</link><guid isPermaLink="true">https://forum.qt.io/post/661357</guid><dc:creator><![CDATA[Oumayma]]></dc:creator><pubDate>Mon, 24 May 2021 19:50:33 GMT</pubDate></item><item><title><![CDATA[Reply to Mouse and QMenuBar on Mon, 24 May 2021 18:01:37 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Why not just disable the menu ?</p>
]]></description><link>https://forum.qt.io/post/661314</link><guid isPermaLink="true">https://forum.qt.io/post/661314</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 24 May 2021 18:01:37 GMT</pubDate></item><item><title><![CDATA[Reply to Mouse and QMenuBar on Mon, 24 May 2021 13:22:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> I want that , if I can deactivate it for a period of time, not forever.</p>
]]></description><link>https://forum.qt.io/post/661280</link><guid isPermaLink="true">https://forum.qt.io/post/661280</guid><dc:creator><![CDATA[Oumayma]]></dc:creator><pubDate>Mon, 24 May 2021 13:22:56 GMT</pubDate></item><item><title><![CDATA[Reply to Mouse and QMenuBar on Mon, 24 May 2021 10:33:12 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
You want the top menus, NOT open the sub menu when clicked ?<br />
How will user then access the sub item ?</p>
]]></description><link>https://forum.qt.io/post/661252</link><guid isPermaLink="true">https://forum.qt.io/post/661252</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Mon, 24 May 2021 10:33:12 GMT</pubDate></item></channel></rss>