Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Customize QTAbBar
Forum Updated to NodeBB v4.3 + New Features

Customize QTAbBar

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 652 Views 2 Watching
  • 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.
  • 2 Offline
    2 Offline
    24unix
    wrote on last edited by
    #1

    Hi, I'm new to the Forum.

    I try to create a KDE app with QT.

    I want it to have a TabBar, like browsers have, with a favicon and a close button.

    But I want the Button to be on the left, default the favicon, and only when the mouse enters the TabItem it should change to a close button.

    Is that possible at all?

    Kind regards.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Well its not directly possible by just adjusting some settings as far as i know.
      You could use
      https://doc.qt.io/qt-5/qtabbar.html#setTabButton

      So you can put a widget on top of it and pretty much
      get it how you want.

         QWidget *oneTab = new QWidget(this);
          auto horizontalLayout = new QHBoxLayout(oneTab);
          horizontalLayout->setContentsMargins(1, 1, 1, 1);
          auto toolButton = new QToolButton(oneTab);
          toolButton->setText("X");
          toolButton->setAutoRaise(true);
          horizontalLayout->addWidget(toolButton);
          auto labText = new QLabel(oneTab);
          labText->setText("TEST");
          horizontalLayout->addWidget(labText);
          auto labIcon = new QLabel(oneTab);
          labIcon->setPixmap(QPixmap(QString::fromUtf8(":/business-together-brain-icon.svg")));
          horizontalLayout->addWidget(labIcon);
      
          ui->tabWidget->tabBar()->setTabButton(0, QTabBar::ButtonPosition::LeftSide, oneTab );
      
      

      alt text

      You might also be able to do it via stylesheets but your
      special button widget that's an icon until the tab is entered might need code. though.

      For knowing when tab is entered, look at
      https://doc.qt.io/qt-5/qwidget.html#enterEvent
      and the leaveEvent

      2 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        Well its not directly possible by just adjusting some settings as far as i know.
        You could use
        https://doc.qt.io/qt-5/qtabbar.html#setTabButton

        So you can put a widget on top of it and pretty much
        get it how you want.

           QWidget *oneTab = new QWidget(this);
            auto horizontalLayout = new QHBoxLayout(oneTab);
            horizontalLayout->setContentsMargins(1, 1, 1, 1);
            auto toolButton = new QToolButton(oneTab);
            toolButton->setText("X");
            toolButton->setAutoRaise(true);
            horizontalLayout->addWidget(toolButton);
            auto labText = new QLabel(oneTab);
            labText->setText("TEST");
            horizontalLayout->addWidget(labText);
            auto labIcon = new QLabel(oneTab);
            labIcon->setPixmap(QPixmap(QString::fromUtf8(":/business-together-brain-icon.svg")));
            horizontalLayout->addWidget(labIcon);
        
            ui->tabWidget->tabBar()->setTabButton(0, QTabBar::ButtonPosition::LeftSide, oneTab );
        
        

        alt text

        You might also be able to do it via stylesheets but your
        special button widget that's an icon until the tab is entered might need code. though.

        For knowing when tab is entered, look at
        https://doc.qt.io/qt-5/qwidget.html#enterEvent
        and the leaveEvent

        2 Offline
        2 Offline
        24unix
        wrote on last edited by
        #3

        @mrjj Many thanks for your reply. I'm currently busy with another issue, but I'll sonn try to understand what you wrote.

        mrjjM 1 Reply Last reply
        0
        • 2 24unix

          @mrjj Many thanks for your reply. I'm currently busy with another issue, but I'll sonn try to understand what you wrote.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @24unix
          Hi
          Ok. np.
          Basically, we just use setTabButton to place a Widget on top of the tab that
          has 1 ToolButton for close and one label for Text and a label to show the icon.
          All in a layout to keep them where we want them.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved