Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Add some customized menuButton on dockWidget titlebar with stylesheet

    General and Desktop
    1
    1
    874
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      simananzhui last edited by

      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);
      

      }

      @

      1 Reply Last reply Reply Quote 0
      • First post
        Last post