0

Clicking right mouse button on any QDockWidget title causes list of all QDockWidget in application. To disable this beheavor I implemented special title class

class QMyTitleBar : public QLabel
{
public:
    QMyTitleBar(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : QLabel(parent, f)
    {
    }

    QMyTitleBar(const QString &text, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : QLabel(text, parent, f)
    {
    }

    ~QMyTitleBar()
    {
    }

protected:
    void mouseReleaseEvent(QMouseEvent * qevent) override
{
    if (qevent->button() == Qt::MouseButton::RightButton)
    {
        qevent->accept();
        return;
    }
}

void mousePressEvent(QMouseEvent * qevent) override
{
    if (qevent->button() == Qt::MouseButton::RightButton)
    {
        qevent->accept();
        return;
    }
}

and set to my QDockWidget this custom title widget

myDockWidget->setTitleBarWidget(new QMyTitleBar(QObject::tr("My Title")));

but this does not work. It handles mouse event but menu with all QDockWidgets appears. How can I remove this menu?

1 Answers1

0

dock_widget->setContextMenuPolicy(Qt::PreventContextMenu);

From: How to disable the context menu of a QDockWidget title bar

Eynix
  • 66
  • 4