PDA

View Full Version : Own defined Dockareas



jobrandt
6th July 2007, 14:22
QMainWindow defines four areas where widgets can be docked.
Is it possible to define my own dockareas?
It should be a component like QFrame that i can place anywere and dock widgets to it.

jpn
7th July 2007, 17:48
QMainWindow defines four areas where widgets can be docked.
Is it possible to define my own dockareas?
It should be a component like QFrame that i can place anywere and dock widgets to it.
No, I'm afraid this is not possible without rewriting the whole main window framework. Define "anywhere"? How would other widgets in the main window layout behave? :)

rajesh
9th July 2007, 14:02
Qt4.3 having 8 dock areas(included corner), but you can dock more than 8.
like you can dock multiple widget in left side, in left1 & left2.

jobrandt
10th July 2007, 19:00
With left1 & left2 etc. i could manage the layout i wanted. I could fix the position of windows that should not be moved.
But there is now another problem: How can set the size and position of docked windows?
This problem was discussed several time in this forum. But there was no solution that really satisfy.
From Delphi i know the element TPanel. It has the property DockSite. If it is set to true you can dock other TPanel to it if the other TPanel has the property DragKind=dkDock.
With TPanel i can do what ever i can do with QFrame.
But I think there is no (easy) way to implement something like TPanel.

rajesh
11th July 2007, 06:21
you can set the size and position of dockwidget using
DockWidgetArea and sizeHint.
I set the size and position of docked windows by using DockWidgetArea and sizeHint.
but sometime you have to change the sizeHint of other widget to fix size of first widget.

jobrandt
13th July 2007, 17:13
How are you using sizeHint?
Here is some code that displays 2 QDockWidget. Docker1 should be displayed at position 100,100 and should have the size 100x200. This works fine.
But i can't set the width of Docker2 to 100.

DockTest::DockTest(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);

QDockWidget *Docker1 = new QDockWidget(this);
Docker1->setObjectName("Docker1");

QFrame *frame1 = new QFrame(Docker1);
QVBoxLayout *la1 = new QVBoxLayout(Docker1);
QListWidget *lw1 = new QListWidget(Docker1);
QPushButton *pb1 = new QPushButton(Docker1);

frame1->setLayout(la1);
la1->addWidget(lw1);
la1->addWidget(pb1);
Docker1->setWidget(frame1);

addDockWidget(Qt::RightDockWidgetArea,Docker1);
Docker1->setFeatures(QDockWidget::DockWidgetFloatable|QDock Widget::DockWidgetMovable);
Docker1->setFloating(true);
Docker1->setGeometry(100,100,100,200);

// --------------------------------------------

QDockWidget *Docker2 = new QDockWidget(this);
Docker2->setObjectName("Docker2");

QFrame *frame2 = new QFrame(this);
QVBoxLayout *la2 = new QVBoxLayout(Docker2);
QListWidget *lw2 = new QListWidget(Docker2);
QPushButton *pb2 = new QPushButton(Docker2);

frame2->setLayout(la2);
la2->addWidget(lw2);
la2->addWidget(pb2);
Docker2->setWidget(frame2);

addDockWidget(Qt::LeftDockWidgetArea,Docker2);
Docker2->setFeatures(QDockWidget::DockWidgetFloatable|QDock Widget::DockWidgetMovable);
Docker2->setFloating(false);
// Docker2 should be displayed with a width of 100
Docker2->setGeometry(10,10,100,100); // does not work
Docker2->setMinimumWidth(100); // does not work

}

rajesh
16th July 2007, 06:34
Hi,
here is the code for you.


DockerDockWidget *Docker2 = new DockerDockWidget(this);
...
class DockerDockWidget : public QDockWidget
{
public:
DockerDockWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0);
virtual QSize sizeHint() const;
virtual QSize minimumSizeHint() const;
private:
QSize szHint, minSzHint;
};

DockerDockWidget::DockerDockWidget(QWidget *parent, Qt::WindowFlags flags)
:QDockWidget(parent, flags)
{
szHint = QSize(100, -1); // this sets initial or default size
minSzHint = QSize(75, 75); // this sets minimum size
}
QSize DockerDockWidget::sizeHint() const
{
return szHint;
}
QSize DockerDockWidget::minimumSizeHint() const
{
return minSzHint;
}

jobrandt
18th July 2007, 10:48
This works good for Qt 4.2.3 . It does not work for Qt 4.3.0. Trolltech told me that there is still a task (tasktracker #168726).