Segmentation fault when using setStyleSheet
- 
@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 onlyQTabWidget. Is that what you are testing? I trust you are copying these statements from actual code.@JonB 
 Yes. I would expect to see my whole tab in black color ( similar to when I color the whole widget in black color)
- 
@lukutis222 I guess you need to set the color on QTabWidget::pane like shown here: https://doc.qt.io/qt-6/stylesheet-examples.html @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 
- 
@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 @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 generatedui_....hfile to see exactly what statement is generated for what object where from the QSS you type in.
- 
@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 generatedui_....hfile to see exactly what statement is generated for what object where from the QSS you type in.@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: 
  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)}");
- 
@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: 
  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)}");@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::panein your code version. It's really hard to keep up if these things are not consistent....
- 
@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: 
  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)}");@lukutis222 And did you also check the generated ui_*.h file like @JonB suggested to see how the style-sheet is set there? 
- 
@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::panein your code version. It's really hard to keep up if these things are not consistent....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)}");
- 
@lukutis222 And did you also check the generated ui_*.h file like @JonB suggested to see how the style-sheet is set there? @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)}");
- 
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)}");- 
Start by using the same copied stuff between the two examples. Don't (at this stage) have, for example, one specifying borderand 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 .uifile is not read at runtime. Theuicgenerates theui_....hfile, the C++ code includes that and callssetupUi(). 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.
 
- 
- 
@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)}");@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...
- 
@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...@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 
- 
@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)}");@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 theborder: none;is irrelevant. How hard can it be to copy? Maybe this is irrelevant, but just maybe it is significant, why take the risk?
- 
@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 @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. 
- 
@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 @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 .uifile gets translated into code.
 

