Greetin开发者_运维知识库gs!
I have a QDialog myDialog;
and want to attach additional information to it using QWidget myDrawer( &myDialog, Qt::Drawer )
. This works fine, except that the drawer always attaches itself to the left side of myDialog. I need it on the right side. And I have no clue how to do that.
Any hints and ideas would be greatly appreciated! Thanks, and best regards, Robin
This is normally done by the OS. Try moving the window close to the left edge of your screen and open the drawer - it should now open on the right-hand side.
Generally, try to avoid using drawers, as they are seemingly being frowned upon and not part of the expected "look and feel" these days anymore.
Update:
Sorry - Correct, they are still in the Human Interace Guidelines, but most developers don't use them anymore. From discussions on several boards and IRC channels it seems that they feel "unnatural" as they are not part of the "window".
To get back to your question; I doubt you can control the side the drawer slides out from Qt. Plus it might make a difference depending on if you are using Cocoa- or Carbon-Qt. At least I couldn't find anything regarding that in the Qt documentation.
In the demos\mainwindow project, there are a few lines (lines 311-314) in mainwindow.cpp:
#ifndef Q_WS_MAC
{ "Black", 0, Qt::LeftDockWidgetArea },
#else
{ "Black", Qt::Drawer, Qt::LeftDockWidgetArea }
I don't have access to OS X right now, but I remember I learnt to change the side of the drawer by the above-mentioned project. So you could playaround with this project in OS X.
this is possible:
but you will have to use QDockWidget as the Qt::Drawer widget; the following code is from a QMainWindow class:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QDockWidget *drawdock = new QDockWidget(this,Qt::Drawer);
this->addDockWidget(Qt::RightDockWidgetArea,drawdock);
}
To change the side of the drawer during runtime:
QMainWindow *mainWindow = qobject_cast<QMainWindow *>(this);
mainWindow->addDockWidget(Qt::BottomDockWidgetArea,drawdock);
The areas could be any one of the DockWidgetAreas
精彩评论