Results 1 to 19 of 19

Thread: QDockWidget-title

  1. #1
    Join Date
    Aug 2006
    Posts
    83

    Default QDockWidget-title

    Hello,

    I'm new in Qt and I have a problem with QDockWidget and the problem is that I can't remove the title bar in QDockWidget. I tried using the pixel metric but it doesn't work. I removed all of dockwidget features (in hope that the bar would go away but it didn't).
    Does anyone have any idea??

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDockWidget-title

    Maybe you could use QSplitter instead of a dock widget? A dock widget without title bar loses almost all of features specific to a dock widget.
    J-P Nurmi

  3. #3
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidget-title

    I know that. I use dockwidget because I have another dockwidget and it can dock under the first dockwidget (forming two dockwidgets together one above the other) and this can be done only if the first one is a dockwidget too.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDockWidget-title

    You can achieve the same kind of functionality with QSplitter, whose orientation is vertical, see QSplitter::setOrientation().
    J-P Nurmi

  5. #5
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidget-title

    QSplitter will not do the trick I need. I'm sure of that. I need QDockWidget. Is there any way to remove the title bar??

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDockWidget-title

    After taking a look at src/gui/widget/dockwidget.cpp, QDockWidgetPrivate::relayout(), I'm afraid it's not possible. The dock widget title bar is not a separate widget. The dockwidget's private layouting mechanism just reserves some space for the title.

    You can set dock widget's features to QDockWidget::NoDockWidgetFeatures to make buttons disappear. You can return return 0 for QStyle::pixelMetric(QStyle::PM_DockWidgetTitleMarg in) to make it thinner than normal. But it will still calculate some minimum height based on font metrics. You can even construct a font with point size 1 (font's point size must be greater than 0) to make the fontmetrics return smaller size, but the title will still appear...
    Last edited by jpn; 23rd August 2006 at 14:48. Reason: Disabled smilies
    J-P Nurmi

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDockWidget-title

    So, how does this differ from having dock widgets with no title bars?

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class MainWindow: public QMainWindow
    4. {
    5. public:
    6. MainWindow(QWidget* parent = 0): QMainWindow(parent)
    7. {
    8. // just some 2 dummy example widgets to fill splitters with
    9. QListWidget* list = new QListWidget;
    10. for (int i = 0; i < 10; ++i)
    11. list->addItem(QString::number(i));
    12. QTableWidget* table = new QTableWidget(4, 1);
    13. for (int r = 0; r < table->rowCount(); ++r)
    14. for (int c = 0; c < table->columnCount(); ++c)
    15. table->setItem(r, c, new QTableWidgetItem(QString::number(r*c+1)));
    16. QLabel* label = new QLabel("central");
    17. label->setAlignment(Qt::AlignCenter);
    18.  
    19. QSplitter* h = new QSplitter(Qt::Horizontal);
    20. QSplitter* v = new QSplitter(Qt::Vertical);
    21. v->addWidget(list);
    22. v->addWidget(table);
    23. h->addWidget(v);
    24. h->addWidget(label);
    25. setCentralWidget(h);
    26. }
    27. };
    28.  
    29. int main(int argc, char *argv[])
    30. {
    31. QApplication a(argc, argv);
    32. MainWindow w;
    33. w.show();
    34. return a.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  8. #8
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidget-title

    Thank you for all your help. I'll try using qsplitter and see if it's ql.

  9. #9
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidget-title

    Ok. Splitter isn't ql because I do need some of dockWidget's features. I don't need to remove the title bar anymore (I fixed this problem), but I don't know that if I can draw a dockwidgetHandle like QToolbarHandle ??? in my own Qstyle

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDockWidget-title

    Quote Originally Posted by moowy
    Ok. Splitter isn't ql because I do need some of dockWidget's features.
    We could be more helpful if you told us exactly what features do you need.

    I don't need to remove the title bar anymore (I fixed this problem), but I don't know that if I can draw a dockwidgetHandle like QToolbarHandle ??? in my own Qstyle
    Sure, you can draw anything you want with styles, you will just have to provide proper style options. See QStyle::draw*() docs. You will have to implement the behaviour yourself. Drawing a handle won't bring you any functionality..

    Are you aware that you can place any widget in a tool bar? Maybe this is more what you're after?
    Attached Images Attached Images
    J-P Nurmi

  11. #11
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidget-title

    Can you maybe help me with the apropriate PE_primitiveElement to use to draw onto QDockWidget titleBar or maybe CE_controlElement ??
    The handle is just for good looks .
    The features I need are float and movable dockwidget

  12. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDockWidget-title

    Override QDockWidget::paintEvent(). Call base class implementation first so that the dock widget gets drawn normally. Then draw your custom thing on top. Take a look at src/gui/widget/qtoolbarhandle.cpp: especially QToolBarHandle::paintEvent() and getStyleOption().

    Qt Code:
    1. void DockWidget::paintEvent(QPaintEvent* event)
    2. {
    3. // let the base class draw first
    4. QDockWidget::paintEvent(event);
    5.  
    6. // maybe use QStyle::pixelMetric() for these?
    7. static const int WIDTH = 10;
    8. static const int HEIGHT = 20;
    9.  
    10. // draw some kind of handle
    11. QStylePainter painter(this);
    12. opt.initFrom(this);
    13. opt.state |= QStyle::State_Horizontal;
    14. opt.rect = QRect(0, 0, WIDTH, HEIGHT);
    15. painter.drawPrimitive(QStyle::PE_IndicatorToolBarHandle, opt);
    16. }
    To copy to clipboard, switch view to plain text mode 

    Edit: What comes to customizing widgets, checking out things done in Qt sources is definitely the most powerful way. It's simply impossible to cover every little detail in the docs. Qt sources are readable and understandable, so use the power of the sources! :)
    Last edited by jpn; 25th August 2006 at 09:43. Reason: added a note
    J-P Nurmi

  13. #13
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidget-title

    Somehow this doesn't do the trick. I already have installed an eventFilter(paint event) on the qdockwidget and I applied the code to it but it doesn't show. Any other ideas??

    I will try using the CE_DockWidgetTitle. I can't believe that I ddin't see it in the QStyle
    Last edited by moowy; 25th August 2006 at 10:40.

  14. #14
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDockWidget-title

    Quote Originally Posted by moowy
    Somehow this doesn't do the trick. I already have installed an eventFilter(paint event) on the qdockwidget and I applied the code to it but it doesn't show. Any other ideas??
    Painting in an event filter is a bit problematic because the event goes FIRST through the filter and THEN to the base class (assuming that the event filter doesn't filter it out). So basically the base class draws over anything you had drawn in the event filter. This kind of painting is possible in event filter only by doing some ugly tricks. Basically you have to deliver the event to the receiver widget by hand and then do the custom painting afterwards. And you will also have to temporarily remove the event filter to avoid an infinite loop.

    Qt Code:
    1. // this is inside an event filter where event type is a paint event..
    2.  
    3. // remove the event filter during sending
    4. // the paint event to avoid an infinite loop
    5. widget->removeEventFilter(this);
    6.  
    7. // send the event and let the widget to draw itself first
    8. QApplication::sendEvent(widget, event);
    9.  
    10. // restore the event filter
    11. widget->installEventFilter(this);
    12.  
    13. // draw your custom things here
    14. QStylePainter painter(widget);
    15. ....
    16.  
    17. // be sure to return true so that the widget doesn't
    18. // receive this paint event and paint itself over again
    19. return true;
    To copy to clipboard, switch view to plain text mode 

    So, I recommend you to simply subclass QDockWidget and override paintEvent()... it will be much simplier and less error prone..
    J-P Nurmi

  15. #15
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidget-title

    I have another problem conserning QDockWidget. In my workspace i have tvo dockwidgets and one other widget. The problem is that these two widgets have their own PE_IndicatorDockWidgetResizeHandle and I only need one. I know how to disable them both but i don't know how to disable just one.

    i tried this code but it doesn't work (if i remove the part with the objectName it disables the both of them)

    if (((widget->inherits("QDockWidgetSeparator")) || (widget->inherits("QDockSeparator"))) && (widget->objectName()=="name"))
    {
    widget->setAttribute(Qt::WA_Disabled);
    }

  16. #16
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidget-title

    Could you maybe tell me how could I get from only a Qwidget his orientation : QStyle::State_Horizontal ????

    Ok. let me be more clear:

    I have a qmainwindow and in it 2 dockwidgets(left,bottom) and a qworkspace.
    the problem is that the left one draws QDockSeparator on the right and on the bottom at his borders. I only want him to draw the QDockSeparator on the bottom border. How could I achieve this???

    please help.
    Last edited by moowy; 28th August 2006 at 11:34.

  17. #17
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidget-title

    Does anyone know how can i fix this?

  18. #18
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDockWidget-title

    Quote Originally Posted by moowy
    I have a qmainwindow and in it 2 dockwidgets(left,bottom) and a qworkspace.
    the problem is that the left one draws QDockSeparator on the right and on the bottom at his borders. I only want him to draw the QDockSeparator on the bottom border. How could I achieve this???
    QDockSeparators are created/shown/hidden on the fly when needed. You cannot delete them or a crash will occur. You will have to monitor for every movement and possibly resize events too, and hide the separator again and again by hand when appropriate.

    You can find the QDockSeparators like this:
    Qt Code:
    1. // Notice this (from qdockseparator_p.h):
    2.  
    3. //
    4. // W A R N I N G
    5. // -------------
    6. //
    7. // This file is not part of the Qt API. It exists purely as an
    8. // implementation detail. This header file may change from version to
    9. // version without notice, or even be removed.
    10. //
    11. // We mean it.
    12. //
    13. #include <private/qdockseparator_p.h>
    14. ...
    15. // notice that QDockSeparators are children of QMainWindow, not children of QDockWidget
    16. foreach (QObject* obj, children())
    17. {
    18. if (QString(obj->metaObject()->className()) == "QDockSeparator")
    19. {
    20. QDockSeparator* sep = qobject_cast<QDockSeparator*>(obj);
    21. if (sep && sep->orientation == Qt::Vertical)
    22. {
    23. ...
    24. }
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  19. #19
    Join Date
    Apr 2014
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QDockWidget-title

    I got rid of the title bar in my DockWidget by setting it to an empty widget:

    Qt Code:
    1. QWidget* myTitle = new QWidget( this );
    2. myDock->setTitleBarWidget( myTitle );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QDockWidget Size
    By kiker99 in forum Qt Programming
    Replies: 9
    Last Post: 31st March 2007, 17:15
  2. QDockWidget flicker
    By fellobo in forum Qt Programming
    Replies: 1
    Last Post: 28th April 2006, 21:42
  3. QTableWidget -> QDockWidget,
    By ogre in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2006, 07:51
  4. QDockWidget: Debugging crash
    By carsten in forum Qt Programming
    Replies: 10
    Last Post: 7th January 2006, 11:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.