MainWindow
::MainWindow(QWidget *parent
){
newAct
->setShortcut
(QObject::tr("Ctrl+N"));
dockAct
->setShortcut
(QObject::tr("Ctrl+D"));
connect(dockAct, SIGNAL(triggered()), this, SLOT(showDockWidget()));
fileMenu->addAction(newAct);
editMenu->addAction(dockAct);
}
MainWindow::~MainWindow()
{}
void MainWindow::showDockWidget()
{
_dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
_dock
->setFeatures
(QDockWidget::AllDockWidgetFeatures);
_dock->setFloating ( true );
_dock->setWidget( btn_1 );
//setWindowFlags( Qt::WStyle_Customize|Qt::WStyle_Title );
_dock->setGeometry( width()/2, height()/2, 100, 30 );
_dock->show();
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QAction* newAct = new QAction(QIcon(":/images/new.png"), QObject::tr("&New"), this);
newAct->setShortcut(QObject::tr("Ctrl+N"));
QAction* dockAct = new QAction(QIcon(":/images/cut.png"), QObject::tr("Show Dock Widget"), this);
dockAct->setShortcut(QObject::tr("Ctrl+D"));
connect(dockAct, SIGNAL(triggered()), this, SLOT(showDockWidget()));
QMenu *fileMenu = menuBar()->addMenu(QObject::tr("&File"));
fileMenu->addAction(newAct);
QMenu *editMenu = menuBar()->addMenu(QObject::tr("&Edit"));
editMenu->addAction(dockAct);
}
MainWindow::~MainWindow()
{}
void MainWindow::showDockWidget()
{
_dock = new QDockWidget(this);
_dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
_dock->setFeatures (QDockWidget::AllDockWidgetFeatures);
_dock->setFloating ( true );
QToolButton* btn_1 = new QToolButton();
_dock->setWidget( btn_1 );
//setWindowFlags( Qt::WStyle_Customize|Qt::WStyle_Title );
_dock->setGeometry( width()/2, height()/2, 100, 30 );
_dock->show();
}
To copy to clipboard, switch view to plain text mode
Bookmarks