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

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

    Update:
    very fast sample.

    class MyTab : public QTabWidget {
      Q_OBJECT
     public:
      explicit MyTab(QWidget* parent = nullptr) : QTabWidget(parent) {}
     protected:
      virtual void paintEvent(QPaintEvent* e ) override {
        QTabWidget::paintEvent(e);
        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.