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. Segmentation fault when using setStyleSheet
Forum Updated to NodeBB v4.3 + New Features

Segmentation fault when using setStyleSheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 5 Posters 2.2k 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.
  • J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on last edited by
    #5

    put the :
    ui->tabWidget->setStyleSheet....

    after the ui->setupUi(this); call.


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    L 1 Reply Last reply
    2
    • J.HilkJ J.Hilk

      put the :
      ui->tabWidget->setStyleSheet....

      after the ui->setupUi(this); call.

      L Offline
      L Offline
      lukutis222
      wrote on last edited by lukutis222
      #6

      Thanks all for quick responses.
      I do not destroy or delete that tab widget anywhere. The structure of my widgets are as following:

      001b05f4-97d4-4891-a6ca-9b7e79fa88d8-image.png

      I have tried to call the setStyleSheet after setuipUI and that fixed my segmentation fault.. However, I would still like to understand about this QTabWidget and why no color is applied.

      I can do:

      ui->tab_3->setStyleSheet("QWidget { background-color: rgb(11, 33, 40);border: 1px solid white;}");
      

      And the color will be applied (blackish color):
      c90b7567-ee54-481e-bd59-c4bccb7642fc-image.png

      When I do:

      ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");
      

      Nothing is styled:
      8ba45435-5d18-4e01-b00f-a20b7b9cac37-image.png

      JonBJ jsulmJ 2 Replies Last reply
      0
      • L lukutis222

        Thanks all for quick responses.
        I do not destroy or delete that tab widget anywhere. The structure of my widgets are as following:

        001b05f4-97d4-4891-a6ca-9b7e79fa88d8-image.png

        I have tried to call the setStyleSheet after setuipUI and that fixed my segmentation fault.. However, I would still like to understand about this QTabWidget and why no color is applied.

        I can do:

        ui->tab_3->setStyleSheet("QWidget { background-color: rgb(11, 33, 40);border: 1px solid white;}");
        

        And the color will be applied (blackish color):
        c90b7567-ee54-481e-bd59-c4bccb7642fc-image.png

        When I do:

        ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");
        

        Nothing is styled:
        8ba45435-5d18-4e01-b00f-a20b7b9cac37-image.png

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #7

        @lukutis222 said in Segmentation fault when using setStyleSheet:

        ui->tab_3->setStyleSheet("QWidget { background-color: rgb(11, 33, 40);border: 1px solid white;}");

        ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");

        The first styles all QWidgets, the second only QTabWidget. Is that what you are testing? I trust you are copying these statements from actual code.

        L 1 Reply Last reply
        0
        • L lukutis222

          Thanks all for quick responses.
          I do not destroy or delete that tab widget anywhere. The structure of my widgets are as following:

          001b05f4-97d4-4891-a6ca-9b7e79fa88d8-image.png

          I have tried to call the setStyleSheet after setuipUI and that fixed my segmentation fault.. However, I would still like to understand about this QTabWidget and why no color is applied.

          I can do:

          ui->tab_3->setStyleSheet("QWidget { background-color: rgb(11, 33, 40);border: 1px solid white;}");
          

          And the color will be applied (blackish color):
          c90b7567-ee54-481e-bd59-c4bccb7642fc-image.png

          When I do:

          ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");
          

          Nothing is styled:
          8ba45435-5d18-4e01-b00f-a20b7b9cac37-image.png

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @lukutis222 I guess you need to set the color on QTabWidget::pane like shown here: https://doc.qt.io/qt-6/stylesheet-examples.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          L 1 Reply Last reply
          0
          • JonBJ JonB

            @lukutis222 said in Segmentation fault when using setStyleSheet:

            ui->tab_3->setStyleSheet("QWidget { background-color: rgb(11, 33, 40);border: 1px solid white;}");

            ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");

            The first styles all QWidgets, the second only QTabWidget. Is that what you are testing? I trust you are copying these statements from actual code.

            L Offline
            L Offline
            lukutis222
            wrote on last edited by
            #9

            @JonB
            Yes. I would expect to see my whole tab in black color ( similar to when I color the whole widget in black color)

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @lukutis222 I guess you need to set the color on QTabWidget::pane like shown here: https://doc.qt.io/qt-6/stylesheet-examples.html

              L Offline
              L Offline
              lukutis222
              wrote on last edited by
              #10

              @jsulm
              Yes but how can I do that in code rather than UI?
              in UI I use

                  /*
                   *     QTabWidget::pane {
                     border: none;
                     background: rgb(25, 33, 40);
                  }
                  */
              

              But how can I add pane in code?

              ui->tabWidget->setStyleSheet("QTabWidget::pane { background-color: rgb(11, 33, 40)}");
              

              I tried below and that changes nothing

              JonBJ 1 Reply Last reply
              0
              • L lukutis222

                @jsulm
                Yes but how can I do that in code rather than UI?
                in UI I use

                    /*
                     *     QTabWidget::pane {
                       border: none;
                       background: rgb(25, 33, 40);
                    }
                    */
                

                But how can I add pane in code?

                ui->tabWidget->setStyleSheet("QTabWidget::pane { background-color: rgb(11, 33, 40)}");
                

                I tried below and that changes nothing

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #11

                @lukutis222
                I don't understand. If you say "in UI I use" (and I assume you mean it works)

                QTabWidget::pane {
                       border: none;
                       background: rgb(25, 33, 40);
                }
                

                then in code you can use setStyleSheet("QTabWidget::pane { border: none; background-color: rgb(25, 33, 40); }"). You can even look in the generated ui_....h file to see exactly what statement is generated for what object where from the QSS you type in.

                L 1 Reply Last reply
                2
                • JonBJ JonB

                  @lukutis222
                  I don't understand. If you say "in UI I use" (and I assume you mean it works)

                  QTabWidget::pane {
                         border: none;
                         background: rgb(25, 33, 40);
                  }
                  

                  then in code you can use setStyleSheet("QTabWidget::pane { border: none; background-color: rgb(25, 33, 40); }"). You can even look in the generated ui_....h file to see exactly what statement is generated for what object where from the QSS you type in.

                  L Offline
                  L Offline
                  lukutis222
                  wrote on last edited by lukutis222
                  #12

                  @JonB
                  When I go to my mainwindow.ui, right click the application window -> Change styleSheet and input the following:

                  QTabWidget::pane {
                         border: none;
                         background: rgb(25, 33, 40);
                  }
                  

                  The style applies:
                  86d34e3f-c48c-4bf9-87b7-fabf20f981a7-image.png

                  I checked the style file:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <ui version="4.0">
                   <class>MainWindow</class>
                   <widget class="QMainWindow" name="MainWindow">
                    <property name="geometry">
                     <rect>
                      <x>0</x>
                      <y>0</y>
                      <width>800</width>
                      <height>600</height>
                     </rect>
                    </property>
                    <property name="windowTitle">
                     <string>MainWindow</string>
                    </property>
                    <widget class="QWidget" name="centralwidget">
                     <layout class="QVBoxLayout" name="verticalLayout_3">
                      <item>
                       <widget class="QTabWidget" name="tabWidget">
                        <property name="styleSheet">
                         <string notr="true">
                      QTabWidget::pane { 
                         border: none;
                         background: rgb(25, 33, 40);
                      }
                  

                  I cannot wrap my head around what is wrong with this and why the style does not apply

                      ui->setupUi(this);
                      ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");
                  
                  JonBJ jsulmJ 2 Replies Last reply
                  0
                  • L lukutis222

                    @JonB
                    When I go to my mainwindow.ui, right click the application window -> Change styleSheet and input the following:

                    QTabWidget::pane {
                           border: none;
                           background: rgb(25, 33, 40);
                    }
                    

                    The style applies:
                    86d34e3f-c48c-4bf9-87b7-fabf20f981a7-image.png

                    I checked the style file:

                    <?xml version="1.0" encoding="UTF-8"?>
                    <ui version="4.0">
                     <class>MainWindow</class>
                     <widget class="QMainWindow" name="MainWindow">
                      <property name="geometry">
                       <rect>
                        <x>0</x>
                        <y>0</y>
                        <width>800</width>
                        <height>600</height>
                       </rect>
                      </property>
                      <property name="windowTitle">
                       <string>MainWindow</string>
                      </property>
                      <widget class="QWidget" name="centralwidget">
                       <layout class="QVBoxLayout" name="verticalLayout_3">
                        <item>
                         <widget class="QTabWidget" name="tabWidget">
                          <property name="styleSheet">
                           <string notr="true">
                        QTabWidget::pane { 
                           border: none;
                           background: rgb(25, 33, 40);
                        }
                    

                    I cannot wrap my head around what is wrong with this and why the style does not apply

                        ui->setupUi(this);
                        ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");
                    
                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #13

                    @lukutis222 said in Segmentation fault when using setStyleSheet:

                    QTabWidget::pane {

                    ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");

                    But now you have gone back to not specifying QTabWidget::pane in your code version. It's really hard to keep up if these things are not consistent....

                    L 1 Reply Last reply
                    0
                    • L lukutis222

                      @JonB
                      When I go to my mainwindow.ui, right click the application window -> Change styleSheet and input the following:

                      QTabWidget::pane {
                             border: none;
                             background: rgb(25, 33, 40);
                      }
                      

                      The style applies:
                      86d34e3f-c48c-4bf9-87b7-fabf20f981a7-image.png

                      I checked the style file:

                      <?xml version="1.0" encoding="UTF-8"?>
                      <ui version="4.0">
                       <class>MainWindow</class>
                       <widget class="QMainWindow" name="MainWindow">
                        <property name="geometry">
                         <rect>
                          <x>0</x>
                          <y>0</y>
                          <width>800</width>
                          <height>600</height>
                         </rect>
                        </property>
                        <property name="windowTitle">
                         <string>MainWindow</string>
                        </property>
                        <widget class="QWidget" name="centralwidget">
                         <layout class="QVBoxLayout" name="verticalLayout_3">
                          <item>
                           <widget class="QTabWidget" name="tabWidget">
                            <property name="styleSheet">
                             <string notr="true">
                          QTabWidget::pane { 
                             border: none;
                             background: rgb(25, 33, 40);
                          }
                      

                      I cannot wrap my head around what is wrong with this and why the style does not apply

                          ui->setupUi(this);
                          ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");
                      
                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      @lukutis222 And did you also check the generated ui_*.h file like @JonB suggested to see how the style-sheet is set there?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      L 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @lukutis222 said in Segmentation fault when using setStyleSheet:

                        QTabWidget::pane {

                        ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");

                        But now you have gone back to not specifying QTabWidget::pane in your code version. It's really hard to keep up if these things are not consistent....

                        L Offline
                        L Offline
                        lukutis222
                        wrote on last edited by
                        #15

                        @JonB

                        Both are not working. I can even call:

                        
                            ui->setupUi(this);
                            ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");
                            ui->tabWidget->setStyleSheet("QTabWidget::pane { background-color: rgb(11, 33, 40)}");
                        
                        JonBJ 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @lukutis222 And did you also check the generated ui_*.h file like @JonB suggested to see how the style-sheet is set there?

                          L Offline
                          L Offline
                          lukutis222
                          wrote on last edited by lukutis222
                          #16

                          @jsulm I assume you are talking about this

                          <?xml version="1.0" encoding="UTF-8"?>
                          <ui version="4.0">
                           <class>MainWindow</class>
                           <widget class="QMainWindow" name="MainWindow">
                            <property name="geometry">
                             <rect>
                              <x>0</x>
                              <y>0</y>
                              <width>800</width>
                              <height>600</height>
                             </rect>
                            </property>
                            <property name="windowTitle">
                             <string>MainWindow</string>
                            </property>
                            <widget class="QWidget" name="centralwidget">
                             <layout class="QVBoxLayout" name="verticalLayout_3">
                              <item>
                               <widget class="QTabWidget" name="tabWidget">
                                <property name="styleSheet">
                                 <string notr="true">QTabWidget::pane { 
                                 border: none;
                                 background: rgb(25, 33, 40);
                              }
                          

                          The above is when I edit style sheet in UI instead of code which seems identical to what I am calling in code and it does not work

                          ui->tabWidget->setStyleSheet("QTabWidget::pane { background-color: rgb(25, 33, 40)}");
                          
                          jsulmJ JonBJ 2 Replies Last reply
                          0
                          • L lukutis222

                            @JonB

                            Both are not working. I can even call:

                            
                                ui->setupUi(this);
                                ui->tabWidget->setStyleSheet("QTabWidget { background-color: rgb(11, 33, 40)}");
                                ui->tabWidget->setStyleSheet("QTabWidget::pane { background-color: rgb(11, 33, 40)}");
                            
                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #17

                            @lukutis222

                            • Start by using the same copied stuff between the two examples. Don't (at this stage) have, for example, one specifying border and compare against the other not specifying border, until you have got both working consistently.

                            • The stuff done in the Designer does not work "by magic". The .ui file is not read at runtime. The uic generates the ui_....h file, the C++ code includes that and calls setupUi(). Logic tells you that you must be able to achieve the same in your "manual" code. So you must be able to reproduce. You have some subtle difference somewhere in what you are coding versus what happens from the Designer stuff, so start by getting them identical before you allow any differences.

                            1 Reply Last reply
                            0
                            • L lukutis222

                              @jsulm I assume you are talking about this

                              <?xml version="1.0" encoding="UTF-8"?>
                              <ui version="4.0">
                               <class>MainWindow</class>
                               <widget class="QMainWindow" name="MainWindow">
                                <property name="geometry">
                                 <rect>
                                  <x>0</x>
                                  <y>0</y>
                                  <width>800</width>
                                  <height>600</height>
                                 </rect>
                                </property>
                                <property name="windowTitle">
                                 <string>MainWindow</string>
                                </property>
                                <widget class="QWidget" name="centralwidget">
                                 <layout class="QVBoxLayout" name="verticalLayout_3">
                                  <item>
                                   <widget class="QTabWidget" name="tabWidget">
                                    <property name="styleSheet">
                                     <string notr="true">QTabWidget::pane { 
                                     border: none;
                                     background: rgb(25, 33, 40);
                                  }
                              

                              The above is when I edit style sheet in UI instead of code which seems identical to what I am calling in code and it does not work

                              ui->tabWidget->setStyleSheet("QTabWidget::pane { background-color: rgb(25, 33, 40)}");
                              
                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #18

                              @lukutis222 said in Segmentation fault when using setStyleSheet:

                              I assume you are talking about this

                              No, I'm not.
                              "generated ui_*.h file" - has nothing to do with XML file you're showing...

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              L 1 Reply Last reply
                              0
                              • jsulmJ jsulm

                                @lukutis222 said in Segmentation fault when using setStyleSheet:

                                I assume you are talking about this

                                No, I'm not.
                                "generated ui_*.h file" - has nothing to do with XML file you're showing...

                                L Offline
                                L Offline
                                lukutis222
                                wrote on last edited by
                                #19

                                @jsulm Can you explain where can I find that magic file you are talking about, because I cannot see it in my project file list

                                jsulmJ JonBJ 2 Replies Last reply
                                0
                                • L lukutis222

                                  @jsulm I assume you are talking about this

                                  <?xml version="1.0" encoding="UTF-8"?>
                                  <ui version="4.0">
                                   <class>MainWindow</class>
                                   <widget class="QMainWindow" name="MainWindow">
                                    <property name="geometry">
                                     <rect>
                                      <x>0</x>
                                      <y>0</y>
                                      <width>800</width>
                                      <height>600</height>
                                     </rect>
                                    </property>
                                    <property name="windowTitle">
                                     <string>MainWindow</string>
                                    </property>
                                    <widget class="QWidget" name="centralwidget">
                                     <layout class="QVBoxLayout" name="verticalLayout_3">
                                      <item>
                                       <widget class="QTabWidget" name="tabWidget">
                                        <property name="styleSheet">
                                         <string notr="true">QTabWidget::pane { 
                                         border: none;
                                         background: rgb(25, 33, 40);
                                      }
                                  

                                  The above is when I edit style sheet in UI instead of code which seems identical to what I am calling in code and it does not work

                                  ui->tabWidget->setStyleSheet("QTabWidget::pane { background-color: rgb(25, 33, 40)}");
                                  
                                  JonBJ Online
                                  JonBJ Online
                                  JonB
                                  wrote on last edited by
                                  #20

                                  @lukutis222 said in Segmentation fault when using setStyleSheet:

                                  ui->tabWidget->setStyleSheet("QTabWidget::pane { background-color: rgb(25, 33, 40)}");

                                  Yet again: start by copying what you have working in the .ui, not assuming that the border: none; is irrelevant. How hard can it be to copy? Maybe this is irrelevant, but just maybe it is significant, why take the risk?

                                  1 Reply Last reply
                                  0
                                  • L lukutis222

                                    @jsulm Can you explain where can I find that magic file you are talking about, because I cannot see it in my project file list

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #21

                                    @lukutis222 said in Segmentation fault when using setStyleSheet:

                                    because I cannot see it in my project file list

                                    Since it's a GENERATED file look in build folder.

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    1
                                    • L lukutis222

                                      @jsulm Can you explain where can I find that magic file you are talking about, because I cannot see it in my project file list

                                      JonBJ Online
                                      JonBJ Online
                                      JonB
                                      wrote on last edited by JonB
                                      #22

                                      @lukutis222 said in Segmentation fault when using setStyleSheet:

                                      Can you explain where can I find that magic file you are talking about, because I cannot see it in my project file list

                                      Never said it was. It is in your build directory, and you can read it in and examine it in Creator. Which BTW is very useful for understanding how your .ui file gets translated into code.

                                      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