Add some customized menuButton on dockWidget titlebar with stylesheet

  • hi
    I try to add some my menuButton on dockWidget titlebar using method <setTitleBarWidget>, mean i builded my dockwidget titlebar, but i found if i did not override the method <paintEvent>, my titlebar would never show, why? Is there some silmple way to do it like using stylesheet?

    BTW, my english is not good, please show me some codes to express your ideas, Thanks.

    [My code clips]


    MyDockTitleBar *myTitleBar= new MyDockTitleBar(testDock);

    void MyDockTitleBar::paintEvent(QPaintEvent*)
    QPainter painter(this);
    QRect rect = this->rect();

    QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
    Q_ASSERT(dw != 0);
    if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
        QSize s = rect.size();
        painter.translate(rect.left(), + rect.width());
    painter.fillRect(rect.left(),, rect.width(), rect.height(), QColor(tr("white")));
    painter.drawPixmap(rect.topRight() - QPoint(closePix.width() + 10, -10), closePix);
    painter.drawPixmap(rect.topRight() - QPoint(minPix.width() + 10 + closePix.width() + 10, -7), minPix);
    painter.drawPixmap(rect.topRight() - QPoint(floatPix.width() + 10 + minPix.width() + 10
                                                + closePix.width() + 10, -10), floatPix);



Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.