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. Background color of QToolBox pages inside a QTabWidget in Windows 7

Background color of QToolBox pages inside a QTabWidget in Windows 7

Scheduled Pinned Locked Moved Solved General and Desktop
qtabwidgetqtoolboxwindows 7stylesheet
15 Posts 4 Posters 8.3k 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.
  • K Offline
    K Offline
    kzarog
    wrote on last edited by
    #1

    Hello all,

    I've been having a problem with the background colour of the pages contained in a QToolBox widget, which is in turn inside a QTabWidget in Windows 7.

    The style of Windows 7 applies a white colour in such a case, but my pages inside QToolBox are stubbornly gray and the button style is different, no matter what I have tried. The same behaviour can be found in QScrollArea widgets.

    I wish to achieve the look of a GroupBox inside the pages of my QToolBox widgets. A visual indication can be seen at http://imgur.com/2jTu6D8.

    The image contains also my tries at achieving the desired look. Currently I have used stylesheets that apply background-color:white or background-color:transparent but the results are not really nice. Using QPalette was also not successful.

    Any help/hints for a platform-agnostic solution (but not necessarily only that) would be greatly appreciated.

    Thank you for your time!

    raven-worxR 1 Reply Last reply
    0
    • K kzarog

      Hello all,

      I've been having a problem with the background colour of the pages contained in a QToolBox widget, which is in turn inside a QTabWidget in Windows 7.

      The style of Windows 7 applies a white colour in such a case, but my pages inside QToolBox are stubbornly gray and the button style is different, no matter what I have tried. The same behaviour can be found in QScrollArea widgets.

      I wish to achieve the look of a GroupBox inside the pages of my QToolBox widgets. A visual indication can be seen at http://imgur.com/2jTu6D8.

      The image contains also my tries at achieving the desired look. Currently I have used stylesheets that apply background-color:white or background-color:transparent but the results are not really nice. Using QPalette was also not successful.

      Any help/hints for a platform-agnostic solution (but not necessarily only that) would be greatly appreciated.

      Thank you for your time!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @kzarog said:

      The image contains also my tries at achieving the desired look. Currently I have used stylesheets that apply background-color:white or background-color:transparent but the results are not really nice. Using QPalette was also not successful.

      you need to specify why they are not successful or not delivering the desired result?! To me it's unclear what you want, since the toolbox has a white background such as the groupbox.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      K 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @kzarog said:

        The image contains also my tries at achieving the desired look. Currently I have used stylesheets that apply background-color:white or background-color:transparent but the results are not really nice. Using QPalette was also not successful.

        you need to specify why they are not successful or not delivering the desired result?! To me it's unclear what you want, since the toolbox has a white background such as the groupbox.

        K Offline
        K Offline
        kzarog
        wrote on last edited by
        #3

        @raven-worx Hi and thanks for your reply!

        I was not clear enough, sorry about that.

        What I want to achieve is to have the colour of the tab (white for Windows 7, as shown inside QGroupBox in the image) in between the toolbox pages (i.e. it not to be gray, as is shown inside QToolBox in the image). This needs to happen without altering the styling of the buttons, which is done when setting the stylesheet to either white or transparent (QToolbox+White, QToolbox+Transparent).

        I hope this is more clear, thanks!

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          ok i hope i understood now what you want.
          Please show your stylesheet. Most probably your stylesheet is too generic and thus it also gets applied to the child widgets.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          K 1 Reply Last reply
          0
          • raven-worxR raven-worx

            ok i hope i understood now what you want.
            Please show your stylesheet. Most probably your stylesheet is too generic and thus it also gets applied to the child widgets.

            K Offline
            K Offline
            kzarog
            wrote on last edited by kzarog
            #5

            @raven-worx Thanks!

            Well, I don't have a specific stylesheet, as I wish to be close to the platform defaults.

            I just use QtCreator to set the stylesheet for the QToolBox by adding (e.g. for white)

            backgound-color:white

            Is there a better way to do this?

            raven-worxR 1 Reply Last reply
            0
            • K kzarog

              @raven-worx Thanks!

              Well, I don't have a specific stylesheet, as I wish to be close to the platform defaults.

              I just use QtCreator to set the stylesheet for the QToolBox by adding (e.g. for white)

              backgound-color:white

              Is there a better way to do this?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @kzarog
              Then try the following stylesheet:

              QToolBox {
              background: transparent;
              }
              

              so it only gets applied to QToolBox instances, and not to the child widgets.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              K 1 Reply Last reply
              0
              • raven-worxR raven-worx

                @kzarog
                Then try the following stylesheet:

                QToolBox {
                background: transparent;
                }
                

                so it only gets applied to QToolBox instances, and not to the child widgets.

                K Offline
                K Offline
                kzarog
                wrote on last edited by
                #7

                @raven-worx Hi again and thank you for your suggestion.

                Unfortunately your solution did not work when trying setting the stylesheet for QToolBox (background or background-color to transparent) or just the QWidget objects inside QToolBox.

                I keep getting the same result to the (QToolBox + transparent) portion of my uploaded image.

                raven-worxR 1 Reply Last reply
                0
                • K kzarog

                  @raven-worx Hi again and thank you for your suggestion.

                  Unfortunately your solution did not work when trying setting the stylesheet for QToolBox (background or background-color to transparent) or just the QWidget objects inside QToolBox.

                  I keep getting the same result to the (QToolBox + transparent) portion of my uploaded image.

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  @kzarog
                  In your screenshot the buttons also have a transparent background applied.
                  When you correctly applied my stylesheet this cant happen for sure.
                  Please show some code, especially where you set the stylesheet.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  K 1 Reply Last reply
                  0
                  • raven-worxR raven-worx

                    @kzarog
                    In your screenshot the buttons also have a transparent background applied.
                    When you correctly applied my stylesheet this cant happen for sure.
                    Please show some code, especially where you set the stylesheet.

                    K Offline
                    K Offline
                    kzarog
                    wrote on last edited by kzarog
                    #9

                    @raven-worx Hi again,

                    I have made a very simple dialog application to demonstrate the issue. The dialog was done in Designer and contains one QTabWidget that contains one QToolbox, whose first page has a QLineEdit and a QPushButton. The code follows:

                    #include "dialog.h"
                    #include "ui_dialog.h"
                    
                    Dialog::Dialog(QWidget *parent) :
                    	QDialog(parent),
                    	ui(new Ui::Dialog)
                    {
                    	ui->setupUi(this);
                    
                    	//	Stylesheet settings I have tried that result in the first dialog image
                    	//this->setStyleSheet("QToolBox {background:transparent}");
                    	//this->setStyleSheet("QToolBox {background-color:transparent}");
                    	//ui->toolBox->setStyleSheet("QToolBox {background: transparent}");
                    	//ui->toolBox->setStyleSheet("QToolBox {background-color: transparent}");
                    
                    	//	Stylesheet setting just for the QPushButton that results in the second dialog image
                    	ui->toolBox->setStyleSheet("QPushButton {background:transparent}");
                    }
                    
                    Dialog::~Dialog()
                    {
                    	delete ui;
                    }
                    

                    The result from each of the commented lines (obviously, each line applied individually each time) gave me the first dialog shown in these two uploaded images.

                    The uncommented stylesheet application (again, with only that line uncommented) works as intended for QPushButton. Also, using something like

                    ui->toolBox->setStyleSheet("QWidget#lineEdit {background:transparent}");
                    

                    correctly applies a transparent background to just the QLineEdit element.

                    QToolbox is just not conforming! Please let me know if I am doing things the wrong way.

                    Thanks

                    raven-worxR 1 Reply Last reply
                    0
                    • K kzarog

                      @raven-worx Hi again,

                      I have made a very simple dialog application to demonstrate the issue. The dialog was done in Designer and contains one QTabWidget that contains one QToolbox, whose first page has a QLineEdit and a QPushButton. The code follows:

                      #include "dialog.h"
                      #include "ui_dialog.h"
                      
                      Dialog::Dialog(QWidget *parent) :
                      	QDialog(parent),
                      	ui(new Ui::Dialog)
                      {
                      	ui->setupUi(this);
                      
                      	//	Stylesheet settings I have tried that result in the first dialog image
                      	//this->setStyleSheet("QToolBox {background:transparent}");
                      	//this->setStyleSheet("QToolBox {background-color:transparent}");
                      	//ui->toolBox->setStyleSheet("QToolBox {background: transparent}");
                      	//ui->toolBox->setStyleSheet("QToolBox {background-color: transparent}");
                      
                      	//	Stylesheet setting just for the QPushButton that results in the second dialog image
                      	ui->toolBox->setStyleSheet("QPushButton {background:transparent}");
                      }
                      
                      Dialog::~Dialog()
                      {
                      	delete ui;
                      }
                      

                      The result from each of the commented lines (obviously, each line applied individually each time) gave me the first dialog shown in these two uploaded images.

                      The uncommented stylesheet application (again, with only that line uncommented) works as intended for QPushButton. Also, using something like

                      ui->toolBox->setStyleSheet("QWidget#lineEdit {background:transparent}");
                      

                      correctly applies a transparent background to just the QLineEdit element.

                      QToolbox is just not conforming! Please let me know if I am doing things the wrong way.

                      Thanks

                      raven-worxR Offline
                      raven-worxR Offline
                      raven-worx
                      Moderators
                      wrote on last edited by
                      #10

                      @kzarog

                      This styles makes the grey areas from your screenshot transparent:

                      ui->toolBox->setStyleSheet(
                      "QToolBox,"
                      "QToolBox > *,"
                      "QToolBox > QScrollArea > #qt_scrollarea_viewport > QWidget {"
                      "background: transparent;"
                       "}"
                      );
                      

                      All the other widgets can then be styled as desired.

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      K 1 Reply Last reply
                      0
                      • raven-worxR raven-worx

                        @kzarog

                        This styles makes the grey areas from your screenshot transparent:

                        ui->toolBox->setStyleSheet(
                        "QToolBox,"
                        "QToolBox > *,"
                        "QToolBox > QScrollArea > #qt_scrollarea_viewport > QWidget {"
                        "background: transparent;"
                         "}"
                        );
                        

                        All the other widgets can then be styled as desired.

                        K Offline
                        K Offline
                        kzarog
                        wrote on last edited by
                        #11

                        @raven-worx Thank you so much! Your suggestion (partially) worked! This is my output. I think I understand what the stylesheet does but as you can see the tab buttons ("Page 1" and "Page 2") also became transparent. I've tried to add something similar to

                        QToolBox::tab {background: button;}
                        

                        to make them take the default normal color but adding something like that resets the whole stylesheet to what I was getting before. Any pointers are greatly appreciated!

                        In any case, thank you for your great help! :)

                        raven-worxR 1 Reply Last reply
                        0
                        • K kzarog

                          @raven-worx Thank you so much! Your suggestion (partially) worked! This is my output. I think I understand what the stylesheet does but as you can see the tab buttons ("Page 1" and "Page 2") also became transparent. I've tried to add something similar to

                          QToolBox::tab {background: button;}
                          

                          to make them take the default normal color but adding something like that resets the whole stylesheet to what I was getting before. Any pointers are greatly appreciated!

                          In any case, thank you for your great help! :)

                          raven-worxR Offline
                          raven-worxR Offline
                          raven-worx
                          Moderators
                          wrote on last edited by raven-worx
                          #12

                          @kzarog
                          ok, then try this:

                          "QToolBox,"
                          "QToolBox > QScrollArea,"
                          "QToolBox > QScrollArea > #qt_scrollarea_viewport,"
                          "QToolBox > QScrollArea > #qt_scrollarea_viewport > QWidget {"
                          "background: transparent;"
                           "}"
                          

                          i am not sure if the selector "QToolBox > QScrollArea > #qt_scrollarea_viewport" is really needed. I can't try it right now.

                          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                          If you have a question please use the forum so others can benefit from the solution in the future

                          K 1 Reply Last reply
                          0
                          • raven-worxR raven-worx

                            @kzarog
                            ok, then try this:

                            "QToolBox,"
                            "QToolBox > QScrollArea,"
                            "QToolBox > QScrollArea > #qt_scrollarea_viewport,"
                            "QToolBox > QScrollArea > #qt_scrollarea_viewport > QWidget {"
                            "background: transparent;"
                             "}"
                            

                            i am not sure if the selector "QToolBox > QScrollArea > #qt_scrollarea_viewport" is really needed. I can't try it right now.

                            K Offline
                            K Offline
                            kzarog
                            wrote on last edited by kzarog
                            #13

                            @raven-worx Your second suggestion solved the problem and gave the desired result.

                            You were correct, the selector "QToolBox > QScrollArea > #qt_scrollarea_viewport" was not needed.

                            Thank you so much for your help!

                            1 Reply Last reply
                            0
                            • FranckynosF Offline
                              FranckynosF Offline
                              Franckynos
                              wrote on last edited by
                              #14

                              Hi, I want change icon of tab when one page is selected (arrow at right) and for the other arrow at bottom.
                              I think it's the same way to do this.

                              I tried :

                              QToolBox > QAbstractButton{
                              	background-image: url(:/icones/deleteRed);
                                  image: url(:/icones/deleteRed);
                              }
                              

                              But nothing happend.

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                MhmRhm
                                wrote on last edited by
                                #15

                                Do this for the widgets inside the ToolBox:

                                widget->setBackgroundRole(QPalette::Base);
                                
                                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