Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 689721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:21:42+00:00 2026-05-14T02:21:42+00:00

I’m using Qt and I have a QTabWidget setup in the Qt Designer Editor,

  • 0

I’m using Qt and I have a QTabWidget setup in the Qt Designer Editor, you can see it in picture 1.

picture 1

As you can see after Tab4 there is an empty space all the way to the right edge, in someway I need to fill that space with a color, like in picture 2 (the best thing would be to be able to set a fading color). Or another solution would be that the tabs float out to cover the whole screen.

picture 2

I use the following stylesheet right now:

QTabWidget::tab-bar {

 }

 QTabBar::tab {
  background: gray;
  color: white;
  padding: 10px;
 }

 QTabBar::tab:selected {
  background: lightgray;
 }

Is there a way to set the background color of the QTabBar using Qt stylesheets? Or can I get the tabs floating out to the edge using Qt stylesheets?

EDIT:
I have been trying the solution that Caleb Huitt – cjhuitt suggested below. I really like the idea of making the tabs expand but can’t get it working.

In Qt Designer Editor I right click on my QTabWidget->”Promote To …” and choose “Base class name”: QTabWidget
“Promoted class name”: ExpandableTabWidget
and then I click add and then Promote.

In the init method of the widget that holds my QTabWidget I set

ui.tabWidget->SetTabsExpanding(true);

Everything is building fine but the QTabbar doesn’t expand.

Am I doing something wrong?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:21:42+00:00Added an answer on May 14, 2026 at 2:21 am

    Both expanding tabs and coloring the background can be accomplished using style sheets.

    For expanding tabs, a style sheet can be applied to the tabs which sets their width to a fraction of the total width of the QTabWidget. Since the style sheet will need to be updated upon resize, it is applied using an event filter. See first example code below.

    Although the background of the tab bar can be set, the tab bar doesn’t fill the entire space above the tab pane. It is the container (or parent widget) which is showing through. To control the coloring of that area, put the QTabWidget in a QWidget and set the style sheet on the container. See second example code below.

    Expanding tabs:

    #include <QtGui>
    
    // Sets the style sheet of the QTabWidget to expand the tabs.
    static void expandingTabsStyleSheet(QTabWidget *tw)
    {
        tw->setStyleSheet(QString("QTabBar::tab { width: %1px; } ")
                          .arg(tw->size().width()/tw->count()));
    }
    
    // On resize events, reapply the expanding tabs style sheet
    class ResizeFilter : public QObject
    {
        QTabWidget *target;
    public:
        ResizeFilter(QTabWidget *target) : QObject(target), target(target) {}
    
        bool eventFilter(QObject *object, QEvent *event)
        {
            if (event->type() == QEvent::Resize)
                expandingTabsStyleSheet(target);
            return false;
        }
    };
    
    
    int main(int argc, char * argv[])
    {
      QApplication app(argc, argv);
    
      QTabWidget *tw = new QTabWidget;
      tw->installEventFilter(new ResizeFilter(tw));
      tw->addTab(new QWidget, "Tab1");
      tw->addTab(new QWidget, "Tab2");
      tw->addTab(new QWidget, "Tab3");
    
      tw->show();
    
      return app.exec();
    }
    

    Background beside tabs:

    #include <QtGui>
    
    int main(int argc, char * argv[])
    {
      QApplication app(argc, argv);
    
      QWidget *container = new QWidget;
      container->setStyleSheet("background: qlineargradient( x1: 0, y1: 0, x2: 1, y2
    : 0, stop: 0 black, stop: 1 blue);");
    
      QHBoxLayout *layout = new QHBoxLayout(container);
      layout->setContentsMargins(0, 0, 0, 0);
    
      QTabWidget *tw = new QTabWidget(container);
      layout->addWidget(tw);
      tw->setStyleSheet(
          "QTabBar::tab { background: gray; color: white; padding: 10px; } "
          "QTabBar::tab:selected { background: lightgray; } "
          "QTabWidget::pane { border: 0; } "
          "QWidget { background: lightgray; } ");
      tw->addTab(new QWidget, "Tab1");
      tw->addTab(new QWidget, "Tab2");
      tw->addTab(new QWidget, "Tab3");
    
      container->show();
    
      return app.exec();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Does anyone know how can I replace this 2 symbol below from the string
I want use html5's new tag to play a wav file (currently only supported
In order to apply a triggered animation to all ToolTip s in my app,
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.