[C++] QTableView, how to remove cell padding?
-
Hello,
I have bought a new PC where I have installed a new environment and with the exact same code I get a different UI visualization as you can see in the image at the end of the message.
The cells are now shown with some padding and rounded borders.As IDE I use VisualStudio 2022 on both PCs.
The differences between the two environments are:
Windows SDK 10 for the old, 11 for the new
Qt 6.2 for the old, 6.7 for the new.Which of those is responsible for the visualization difference?
Would I want to stay updated and going on with the newer versions, how do I get rid of the paddings and rounded corners?
I'm not able to find any method, both in QTableView and QTableWidget, to manage those aspects.Both of the screenshots have been taken running the software on the new PC, but the first is a version compiled on the old PC with the old environment, the second is compiled on the new PC with the updated environment, using the same code.
-
Qt 6.7 got a new theme for windows 11. Start your app with the windowsvista theme (-style windowsvista) to get the old windows 10 theme.
-
If you think it's a bug, do report it at https://bugreports.qt.io/
-
Qt 6.7 got a new theme for windows 11. Start your app with the windowsvista theme (-style windowsvista) to get the old windows 10 theme.
@Christian-Ehrlicher said in [C++] QTableView, how to remove cell padding?:
Qt 6.7 got a new theme for windows 11. Start your app with the windowsvista theme (-style windowsvista) to get the old windows 10 theme.
Do you mean as a parameter to add to the executable file?
-
@Christian-Ehrlicher said in [C++] QTableView, how to remove cell padding?:
Qt 6.7 got a new theme for windows 11. Start your app with the windowsvista theme (-style windowsvista) to get the old windows 10 theme.
Do you mean as a parameter to add to the executable file?
-
If you think it's a bug, do report it at https://bugreports.qt.io/
@cristian-adam said in [C++] QTableView, how to remove cell padding?:
If you think it's a bug, do report it at https://bugreports.qt.io/
I would be careful with calling this a bug. Qt tries to use the default OS theme if possible. Sometimes they just lack behind a little bit. If the new Windows style is what we see with Qt 6.7, it is a choice of Microsoft and not of Qt. In general it is a good idea to have your own app a) look modern and b) look like all the other apps people might install. You might disagree with the design choices of Microsoft, but it is still a good idea to go along with it. (Disclaimer: I don't know if the design of Qt 6.7 is actually a design change of Windows.)
However, if you insist on changing it by yourself: If you have a QTableWidget you can get the individual QTableWidgetItems. My guess is that these need to be styled. The easiest (and most reliable way in Qt) is to use stylesheets (most likely a single style sheet for the QTableWidget just styling the QTableWidgetItems will do). You can also have a look at QStyleItemDelegate to change the look of the cells.
-
I am willing to use the css way. Is there a list of the available selectors for the QTableView?
Reading the docuementation I can only find a few as example.@Alhazred said in [C++] QTableView, how to remove cell padding?:
Reading the docuementation I can only find a few as example
It supports the ones it claims to support :)
Note: Qt StyleSheet is not fully CSS. Not everything is possible with Qt StyleSheet. -