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.
  • 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 Offline
    JonBJ Offline
    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 Offline
        JonBJ Offline
        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 Offline
                JonBJ Offline
                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 Offline
                      JonBJ Offline
                      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 Offline
                          JonBJ Offline
                          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