PDA

View Full Version : Click and drag for QMenuBar



M. Bashir
12th May 2011, 10:48
Hi guys,

I want to make my application support click & drag option on QMenuBar because I'm using Qt::Window | Qt::CustomizeWindowHint flags.

How can I add click & option for QMenuBar?

PS
See the attachment plz (screenshot & snippet)
6406

high_flyer
12th May 2011, 10:52
You can turn it to a QToolBar.

M. Bashir
12th May 2011, 11:25
You can turn it to a QToolBar.

Thx, it seems that my question wasn't clear.

I want to simulate the behavior of title bar on menu bar.

high_flyer
12th May 2011, 11:37
Why not just use QToolBar then?

M. Bashir
12th May 2011, 12:34
Why not just use QTitleBar then?

Dude there no class such like it?!!!!

high_flyer
12th May 2011, 13:08
I meant QToolBar of course...

M. Bashir
12th May 2011, 13:31
I meant QToolBar of course...

OK, but QToolBar doesn't have suitable signals for simulating title bar behavior! I'm looking for something like this (it's just a pseudo):


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
ui->setupUi(this);

QHBoxLayout *lay = new QHBoxLayout();
lay->setContentsMargins(0,0,0,0);
lay->addWidget(ui->menuBar);
lay->addWidget(ui->widget_buttons);
ui->toolBar->setLayout(lay);
connect(ui->menuBar, SIGNAL(clicked()), this, SLOT(setPoint()));
connect(ui->menuBar, SIGNAL(mouseMove()), this, SLOT(setCoordinates()));
}
void MainWindow::setPoint()
{
point = cursor().pos();
ui->statusBar->setWindowTitle(QString("X:%1 - Y:%2").arg(point.x()).arg(point.y()));
}

high_flyer
12th May 2011, 13:54
Oh now I see what you want...
You want a custom title bar... I thought you want to be able to move your QMenuBar...

There is no way around it - you will have to subclass what ever you use as your titlebar (QMenuBar in your case), and implement the functionality you need there.