Draw in an empty QTabWidget

  • HI, I was wondering how to draw in an empty QTabWidget.
    I noticed that when a QTabWidget has no tabs it's just a white widget with nothing in it, I was wondering how to draw some texts over it and when the user creates a tab it disappears?

  • Qt Champions 2017

    Then you must subclass it and override paintEvent
    and handle the no tab logic.

    very fast sample.

    class MyTab : public QTabWidget {
      explicit MyTab(QWidget* parent = nullptr) : QTabWidget(parent) {}
      virtual void paintEvent(QPaintEvent* e ) override {
        QPainter painter(this);
        if ( ! count() ) // has no tabs
            painter.drawText( rect(), Qt::AlignCenter, "EMPTY");

    alt text

Log in to reply

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