Results 1 to 19 of 19

Thread: QDockWidget-title

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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

  2. #2
    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??

  3. #3
    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 13:48. Reason: Disabled smilies
    J-P Nurmi

  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

    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

  5. #5
    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.

  6. #6
    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

  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

    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

  8. #8
    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

  9. #9
    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 08:43. Reason: added a note
    J-P Nurmi

  10. #10
    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 09:40.

  11. #11
    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

  12. #12
    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);
    }

Similar Threads

  1. QDockWidget Size
    By kiker99 in forum Qt Programming
    Replies: 9
    Last Post: 31st March 2007, 16:15
  2. QDockWidget flicker
    By fellobo in forum Qt Programming
    Replies: 1
    Last Post: 28th April 2006, 20:42
  3. QTableWidget -> QDockWidget,
    By ogre in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2006, 06:51
  4. QDockWidget: Debugging crash
    By carsten in forum Qt Programming
    Replies: 10
    Last Post: 7th January 2006, 10: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.