I don't know why I parented the actions on mainwindow. Think it was an over site.
I sat down and made a few changes after re-re-reviewing the documentation and got something working for the most part. I still can get it into the mode were it will not display the menu when floating which is not good at all... but it works. The ultimate goal is to have the menu show when the user right clicks the mouse when over the title bar (docked or floating).
#ifndef VIEW_H
#define VIEW_H
#include <QDockWidget>
class MainWindow;
{
Q_OBJECT;
public:
View(MainWindow * mainWindow, std::string const & title);
virtual ~View(void);
private slots:
void onFloat();
void onDock();
void contextMenu
(QPoint const & point
);
private:
};
#endif
#ifndef VIEW_H
#define VIEW_H
#include <QDockWidget>
class QMenu;
class QAction;
class MainWindow;
class View : public QDockWidget
{
Q_OBJECT;
public:
View(MainWindow * mainWindow, std::string const & title);
virtual ~View(void);
private slots:
void onFloat();
void onDock();
void contextMenu(QPoint const & point);
private:
QMenu *m_actionMenu;
QAction *m_actionFloat;
QAction *m_actionDock;
};
#endif
To copy to clipboard, switch view to plain text mode
#include "View.h"
#include "MainWindow.h"
#include <QMenu>
#include <QAction>
#include <QContextMenuEvent>
View::View(MainWindow * mainWindow, std::string const & title)
{
std::string group = "gui/dock/";
group += windowTitle().toStdString();
setObjectName(windowTitle() + "_view");
m_actionMenu
= new QMenu();
m_actionFloat
= new QAction(tr
("Floating"),
this);
m_actionFloat->setCheckable(true);
connect(m_actionFloat, SIGNAL(triggered()), this, SLOT(onFloat()));
m_actionMenu->addAction(m_actionFloat);
m_actionDock
= new QAction(tr
("Dock"),
this);
m_actionDock->setCheckable(true);
connect(m_actionDock, SIGNAL(triggered()), this, SLOT(onDock()));
m_actionMenu->addAction(m_actionDock);
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this,
SIGNAL(customContextMenuRequested
(QPoint const &)),
this,
SLOT(contextMenu
(QPoint const &)));
}
View::~View(void)
{
std::string group = "gui/dock/";
group += windowTitle().toStdString();
}
void View
::contextMenu(QPoint const & point
) {
m_actionMenu->exec(mapToGlobal(point));
}
void View::onFloat()
{
setFloating(true);
setAllowedAreas(Qt::NoDockWidgetArea);
m_actionFloat->setChecked(true);
m_actionDock->setChecked(false);
}
void View::onDock()
{
setAllowedAreas(Qt::AllDockWidgetAreas);
m_actionFloat->setChecked(false);
m_actionDock->setChecked(true);
}
#include "View.h"
#include "MainWindow.h"
#include <QMenu>
#include <QAction>
#include <QContextMenuEvent>
View::View(MainWindow * mainWindow, std::string const & title)
: QDockWidget(title.c_str(), mainWindow, 0)
{
std::string group = "gui/dock/";
group += windowTitle().toStdString();
setObjectName(windowTitle() + "_view");
m_actionMenu = new QMenu();
m_actionFloat = new QAction(tr("Floating"), this);
m_actionFloat->setCheckable(true);
connect(m_actionFloat, SIGNAL(triggered()), this, SLOT(onFloat()));
m_actionMenu->addAction(m_actionFloat);
m_actionDock = new QAction(tr("Dock"), this);
m_actionDock->setCheckable(true);
connect(m_actionDock, SIGNAL(triggered()), this, SLOT(onDock()));
m_actionMenu->addAction(m_actionDock);
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint const &)),
this, SLOT(contextMenu(QPoint const &)));
}
View::~View(void)
{
std::string group = "gui/dock/";
group += windowTitle().toStdString();
}
void View::contextMenu(QPoint const & point)
{
m_actionMenu->exec(mapToGlobal(point));
}
void View::onFloat()
{
setFloating(true);
setFeatures(QDockWidget::DockWidgetFloatable);
setAllowedAreas(Qt::NoDockWidgetArea);
m_actionFloat->setChecked(true);
m_actionDock->setChecked(false);
}
void View::onDock()
{
setFeatures(QDockWidget::AllDockWidgetFeatures);
setAllowedAreas(Qt::AllDockWidgetAreas);
m_actionFloat->setChecked(false);
m_actionDock->setChecked(true);
}
To copy to clipboard, switch view to plain text mode
Bookmarks