PDA

View Full Version : QDockWidgetTitle



moowy
7th September 2006, 10:48
Hello

Can anyone help me with qdockwidget-title. The problem is that I want to put a qtoolbar element inside it, but I have no idea how. Any ideas?

wysota
7th September 2006, 11:24
Inside the title? Can you provide a screenshot?

moowy
7th September 2006, 11:57
I can't because I don't know how to do-it. I want to put a QToolbar inside the CE_DockWidgetTitle area. Does anyone have any clue how to achieve this.

wysota
7th September 2006, 12:56
It will not be easy. Lots of coding. I guess it might be easy to hide the title bar at all and implement a new one containing the toolbar. But why do you need such a strange widget? Can't you have a toolbar under the title bar?

moowy
7th September 2006, 13:13
I tried to hiding the qdockwidget-title area but there are still some pixels of space generated for that area. I need this widget to be a qdockwidget, but I don't need a CE_dockwidgettitle area. If I can't shut the title area off I must implement toolbar inside the title area. Any ideas? Any help would be really appreciated.

jpn
7th September 2006, 13:37
As I already stated in this thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-qdockwidget-title-3393.html#6), the dock widget title bar is not a separate widget. The dockwidget's private layouting mechanism just reserves some space for the title bar and paints buttons etc. inside this reserved area. There is no way to remove it completely. It has been hardcoded into src/gui/widget/dockwidget.cpp, QDockWidgetPrivate::relayout().

Placing a toolbar inside a dock widget doesn't make any sense to me. But oh well, sure you can create a QToolBar object as a child of QDockWidget and manually resize/relocate it during every resize event. You can compare the geometries of the dock widget itself and the widget contained by the dock widget to get proper geometry for the toolbar.

moowy
7th September 2006, 13:57
Thank you. I'll try to move it accordingly to geometry

moowy
7th September 2006, 14:54
It doesn't work. I have a QToolbar inside a QMainWindow inside QDockWidget. I try setting setGeometry on qmainwindow but it doesn't move to the dockwidget-title area. Any other ideas?

wysota
7th September 2006, 15:24
The toolbar has to be stand-alone, not inside the main window (it has to be a direct child of the dock widget).

moowy
7th September 2006, 15:35
Ok. But how can I add a toolbar to a qdockwidget. QMainWindow has addToolbar method, but QDockWidget doesn't. What do you think?

jpn
7th September 2006, 17:09
Ok. But how can I add a toolbar to a qdockwidget. QMainWindow has addToolbar method, but QDockWidget doesn't. What do you think?
Just create a new QToolBar and pass the dock widget as parent.

I meant something like this:


class MyDockWidget : public QDockWidget
{
public:
MyDockWidget(QWidget* parent = 0);

protected:
void resizeEvent(QResizeEvent* event);

private:
QToolBar* toolBar;
}




MyDockWidget::MyDockWidget(QWidget* parent = 0) : QDockWidget(parent)
{
// create toolbar widget as child of the dockwidget
// so it will be placed inside the dockwidget
toolBar = new QToolBar(this);
}

void MyDockWidget::resizeEvent(QResizeEvent* event)
{
QDockWidget::resizeEvent(event);

// set toolbar's geometry so that it covers the whole are above
// the widget which has been set as dock widget's insider
QRect r = geometry;
r.setBottom(widget()->geometry().top());
toolBar->setGeometry(r);
}


Just be aware that the toolbar widget will naturally "steal" all events which would otherwise go to the dock widget's title area. This includes all mouse events and so on, and will break for example the movement functionality of the dock widget. To avoid this, you would have to filter appropriate toolbar's events and deliver them to the dock widget instead.

Edit: I would rather draw something custom to the title bar area instead of adding another widget there. This would require overriding of QDockWidget::paintEvent(). I have already shown you in earlier threads related to this, how to draw custom things with QStyle.

moowy
8th September 2006, 08:43
It works!! Thank you so much jpn. I'm really gratefull. If we ever meet I'll buy you a beer. ;)