Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Tab Widget - Tab Height to accommodate 2-line tab names?
Forum Updated to NodeBB v4.3 + New Features

Tab Widget - Tab Height to accommodate 2-line tab names?

Scheduled Pinned Locked Moved Language Bindings
2 Posts 2 Posters 3.7k Views 1 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.
  • A Offline
    A Offline
    Alabaster
    wrote on last edited by
    #1

    PyQt4 and/or PySide / Python 3 / Windows

    Is it possible to resize the height of a tab bar in order to fit 2-lines of text in the tab names?

    (Better yet, is it possible to have a tab bar resize its height dynamically based on the number of lines of text?)

    Thanks

    1 Reply Last reply
    0
    • jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on last edited by
      #2

      You could do this using style sheets to get a static height, however the following method shows how to have the tab bar dynamically size to the text by inserting QLabels:

      @
      from PyQt4.QtGui import *

      class TabWidget(QTabWidget):
      def addTab(self, widget, text):
      i=QTabWidget.addTab(self, widget, "")
      self.tabBar().setTabButton(i, QTabBar.LeftSide, QLabel(text, self))

      class Widget(QWidget):
      def init(self, parent=None):
      QWidget.init(self, parent)

          l=QVBoxLayout(self)
      
          t=TabWidget(self)
          t.addTab(QWidget(self), "Tab\n1")
          t.addTab(QWidget(self), "Tab 2")
          t.addTab(QWidget(self), "Tab\n3")
      
          l.addWidget(t)
      

      if name=="main":
      from sys import argv, exit
      a=QApplication(argv)
      w=Widget()
      w.show()
      w.raise_()
      exit(a.exec_())
      @

      Hope this helps.

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      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