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);
    testDock->setTitleBarWidget(myTitleBar);

    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();
        s.transpose();
        rect.setSize(s);
    
        painter.translate(rect.left(), rect.top() + rect.width());
        painter.rotate(-90);
        painter.translate(-rect.left(), -rect.top());
    }
    
    painter.fillRect(rect.left(), rect.top(), 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.