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. [SOLVED] QTableWidget stylesheet not working in QTabWidget
QtWS25 Last Chance

[SOLVED] QTableWidget stylesheet not working in QTabWidget

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 12.2k Views
  • 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.
  • H Offline
    H Offline
    HuXiKa
    wrote on last edited by
    #1

    Hello folks.

    I don't no whether i'm missing something, or what I want to achive is impossible. I've created a little "example":http://huxi.uw.hu/hidden/Qt/styletest.tgz which demonstrates my problem. I have a QTableWidget in my MainWindow, and I have a QTableWidget in a QTabWidget, and the tab widget sits in a QDialog. No matter where I set the style sheet for the table widget in the dialog, it won't show up. The same stylesheet works fine for the table widget in the main window, and if I remove the tab widget, and just put my table in the dialog, the stylesheet is active again (try out for yourselfes).
    Any help is appreciated.

    Thanks in advance!

    If you can find faults of spelling in the text above, you can keep them.

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      i tried it on windows 7 and i have the same behaviour.

      could be because of subclassing :
      "Link to the docs":http://doc.qt.nokia.com/4.7-snapshot/stylesheet-syntax.html

      bq. Inheritance
      In classic CSS, when font and color of an item is not explicitly set, it gets automatically inherited from the parent. When using Qt Style Sheets, a widget does not automatically inherit its font and color setting from its parent widget.
      For example, consider a QPushButton inside a QGroupBox:

      @qApp->setStyleSheet("QGroupBox { color: red; } ");@

      bq. The QPushButton does not have an explicit color set. Hence, instead of inheriting color of its parent QGroupBox, it has the system color. If we want to set the color on a QGroupBox and its children, we can write:

      @ qApp->setStyleSheet("QGroupBox, QGroupBox * { color: red; }");@

      bq. In contrast, setting a font and propagate using QWidget::setFont() and QWidget::setPalette() propagates to child widgets

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • H Offline
        H Offline
        HuXiKa
        wrote on last edited by
        #3

        But I'm setting the style of QHeaderView and QTableWidget, not the QTabWidget which contains them. I"m still unable to set any kind of stylesheet for that tablewidget.

        If you can find faults of spelling in the text above, you can keep them.

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          I'm not able to test some things at the moment because i'm mobile. I'll try again tomorrow.

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #5

            Hi HuXiKa,

            I'm back and I have your solution.

            This is what I did (following the link to the docs I gave you) :
            I deleted all stylesheets in both ui files and added one (long) line of code in the main.cpp to get that stylesheet for all widgets in your application (that's the goal of stylesheets, isn't it?)

            @
            a.setStyleSheet("QHeaderView::section, QHeaderView::section * {background-color: qlineargradient
            (x1:0, y1:0, x2:0, y2:1, stop:0 #616161, stop: 0.5 #505050, stop: 0.6 #434343, stop:1 #656565);
            color: white; padding-left: 4px; border: 1px solid #6c6c6c;}");@

            of course you can do the same with the QTableWidget.

            Cheers,

            Eddy

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply
            0
            • H Offline
              H Offline
              HuXiKa
              wrote on last edited by
              #6

              Thank you, this really solved the problem. To bad this can't be achieved with the designer, and you have to write this extra line in the main. Oh well, it works, that's what matters :)

              If you can find faults of spelling in the text above, you can keep them.

              1 Reply Last reply
              0
              • EddyE Offline
                EddyE Offline
                Eddy
                wrote on last edited by
                #7

                you're welcome

                bq. To bad this can’t be achieved with the designer

                Just a little bit of code to have the stylesheet all over your application, or changing it on ever dialog.
                I know what i prefer. ;)

                Qt Certified Specialist
                www.edalsolutions.be

                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