Results 1 to 10 of 10

Thread: Qtableview margin/padding

  1. #1
    Join Date
    Feb 2021
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt5
    Platforms
    Windows

    Default Qtableview margin/padding

    Hi Team

    I have a small problem with tableview.
    The problem I have is that the QT designer view and the actual application view differ (as shown in the in the pic below).
    The table is somehow split in two columns, but when populating all data appears on the left side, including scroll bars.
    After import of my data, these views stay the same. My data appears in the left field (with scroll adjuster) whilst the right field stays blank.

    Attachment 13598
    Does anybody know what setting may need to change in QTdesigner (or in my code) to resolve this?

    Qt Code:
    1. from PyQt5 import QtCore, QtWidgets, uic
    2. from PyQt5.QtCore import Qt
    3. from PyQt5.QtGui import *
    4. from PyQt5.QtWidgets import (qApp, QComboBox, QMainWindow, QApplication, QMessageBox, QFileDialog)
    5.  
    6. #define class
    7. class Bathyui(QtWidgets.QDialog):
    8. def __init__(self, parent=None):
    9. super(Bathyui, self).__init__(parent)
    10. uic.loadUi('Open_File_UWN_Model.ui', self)
    11.  
    12. #connect to widget
    13. self.table = QtWidgets.QTableView(self.tableView)
    14.  
    15. #populate with dataframe
    16. self.table.setModel(file_reader)
    To copy to clipboard, switch view to plain text mode 

    Below the .ui code
    Attachment 13599

    Im a littlebit lost how to solve this. I pretty much hit every setting in the QT Designer formatting menu.
    Im using anaconda python with qt designer 5.11.1 included

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,884
    Thanks
    274
    Thanked 794 Times in 784 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qtableview margin/padding

    For one thing, why are you not using layouts for such a complex form? It looks like you have put every widget in place with absolute size and positioning. This will almost certainly result in headaches if you resize the window or deploy it on a PC with different default magnification. Other than that bad problem, I don't see anything wrong with your UI file.

    I am not a Python expert, but isn't line 13 creating a second QTableView using the current self.tableView as its parent? This is probably why you are seeing two tables. The left-hand table is this new one, which is getting filled from your model, while the original table created from the UI file is underneath it and in the size you specified in the UI file.

    Get rid of line 13 and in line 16 use "self.tableView" to set the model.
    Last edited by d_stranz; 24th February 2021 at 18:48.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    Zoner (25th February 2021)

  4. #3
    Join Date
    Feb 2021
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt5
    Platforms
    Windows

    Default Re: Qtableview margin/padding

    That was indeed the solution, and it looks like I need to go down the same road for some pyvistaqt graphs.
    I reckon Im still struggling with the widgets.

    Thanks for the tip with the layout form, I wondered why I couldnt read it right on my laptop, another one to add to my reading list.

    thanks d_stranz
    really appreciated!

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,884
    Thanks
    274
    Thanked 794 Times in 784 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qtableview margin/padding

    another one to add to my reading list
    Look at the many examples in the Qt distribution. Almost all of the desktop-oriented GUI apps with anything more than a simple UI use them.

    My go-to layout for most dialogs and other form-like widget is QGridLayout. You can make particular use of the ability for a widget to span more than one grid cell and to use horizontal and vertical spacers to squish things down to preferred sizes. Be sure to set a layout for the entire widget so that when the widget is resized, everything in it gets laid out appropriately. Try to avoid setting absolute size limits for widgets unless you can't get them to behave by any other way.

    another one to add to my reading list
    Look at the many examples in the Qt distribution. Almost all of the desktop-oriented GUI apps with anything more than a simple UI use them.

    My go-to layout for most dialogs and other form-like widget is QGridLayout. You can make particular use of the ability for a widget to span more than one grid cell and to use horizontal and vertical spacers to squish things down to preferred sizes. Be sure to set a layout for the entire widget so that when the widget is resized, everything in it gets laid out appropriately. Try to avoid setting absolute size limits for widgets unless you can't get them to behave by any other way.


    Added after 1 36 minutes:


    For fun I decided to edit your UI form to add some layouts, but for some reason the forum links to attach files aren't working for me. So, here's the text of the UI file itself. You can copy and paste it into an empty document and save it with a .ui extension.

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>Form</class>
    4. <widget class="QWidget" name="Form">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>584</width>
    10. <height>585</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>Select Bathy File</string>
    15. </property>
    16. <layout class="QGridLayout" name="gridLayout_2">
    17. <item row="0" column="0">
    18. <layout class="QGridLayout" name="gridLayout">
    19. <item row="3" column="0">
    20. <widget class="QLabel" name="Lat_label">
    21. <property name="text">
    22. <string>Latitude</string>
    23. </property>
    24. </widget>
    25. </item>
    26. <item row="3" column="7">
    27. <widget class="QSpinBox" name="SkipRows"/>
    28. </item>
    29. <item row="6" column="0" colspan="8">
    30. <widget class="QGraphicsView" name="graphicsView"/>
    31. </item>
    32. <item row="3" column="3">
    33. <widget class="QComboBox" name="Combo_Y"/>
    34. </item>
    35. <item row="3" column="1">
    36. <widget class="QComboBox" name="Combo_X"/>
    37. </item>
    38. <item row="3" column="4">
    39. <widget class="QLabel" name="Depth_Label">
    40. <property name="text">
    41. <string>Depth</string>
    42. </property>
    43. </widget>
    44. </item>
    45. <item row="4" column="0" colspan="8">
    46. <widget class="QTableView" name="tableView">
    47. <property name="autoFillBackground">
    48. <bool>true</bool>
    49. </property>
    50. <property name="frameShape">
    51. <enum>QFrame::StyledPanel</enum>
    52. </property>
    53. <property name="sizeAdjustPolicy">
    54. <enum>QAbstractScrollArea::AdjustToContents</enum>
    55. </property>
    56. <property name="autoScrollMargin">
    57. <number>10</number>
    58. </property>
    59. <property name="editTriggers">
    60. <set>QAbstractItemView::NoEditTriggers</set>
    61. </property>
    62. <property name="showDropIndicator" stdset="0">
    63. <bool>true</bool>
    64. </property>
    65. <property name="textElideMode">
    66. <enum>Qt::ElideRight</enum>
    67. </property>
    68. <property name="showGrid">
    69. <bool>true</bool>
    70. </property>
    71. <property name="cornerButtonEnabled">
    72. <bool>true</bool>
    73. </property>
    74. <attribute name="horizontalHeaderDefaultSectionSize">
    75. <number>70</number>
    76. </attribute>
    77. <attribute name="horizontalHeaderStretchLastSection">
    78. <bool>true</bool>
    79. </attribute>
    80. </widget>
    81. </item>
    82. <item row="2" column="4">
    83. <widget class="QRadioButton" name="Other_radioButton_4">
    84. <property name="text">
    85. <string>Other</string>
    86. </property>
    87. </widget>
    88. </item>
    89. <item row="3" column="6">
    90. <widget class="QLabel" name="Skip_row_label">
    91. <property name="text">
    92. <string>Skip Rows</string>
    93. </property>
    94. <property name="buddy">
    95. <cstring>SkipRows</cstring>
    96. </property>
    97. </widget>
    98. </item>
    99. <item row="7" column="0" colspan="8">
    100. <widget class="QDialogButtonBox" name="OK_buttonBox">
    101. <property name="orientation">
    102. <enum>Qt::Horizontal</enum>
    103. </property>
    104. <property name="standardButtons">
    105. <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
    106. </property>
    107. </widget>
    108. </item>
    109. <item row="3" column="5">
    110. <widget class="QComboBox" name="Combo_Z"/>
    111. </item>
    112. <item row="2" column="1">
    113. <widget class="QRadioButton" name="Comma_radioButton_2">
    114. <property name="text">
    115. <string>Comma</string>
    116. </property>
    117. <property name="checked">
    118. <bool>true</bool>
    119. </property>
    120. </widget>
    121. </item>
    122. <item row="3" column="2">
    123. <widget class="QLabel" name="Long_Label">
    124. <property name="text">
    125. <string>Longitude</string>
    126. </property>
    127. </widget>
    128. </item>
    129. <item row="2" column="3">
    130. <widget class="QRadioButton" name="SPACE_radioButton_3">
    131. <property name="text">
    132. <string>SPACE</string>
    133. </property>
    134. </widget>
    135. </item>
    136. <item row="2" column="0">
    137. <widget class="QLabel" name="label_2">
    138. <property name="text">
    139. <string>Delimiter</string>
    140. </property>
    141. </widget>
    142. </item>
    143. <item row="2" column="5">
    144. <widget class="QLineEdit" name="Delimeter_text">
    145. <property name="enabled">
    146. <bool>false</bool>
    147. </property>
    148. <property name="maxLength">
    149. <number>2</number>
    150. </property>
    151. </widget>
    152. </item>
    153. <item row="2" column="2">
    154. <widget class="QRadioButton" name="TAB_radioButton">
    155. <property name="text">
    156. <string>TAB</string>
    157. </property>
    158. </widget>
    159. </item>
    160. <item row="3" column="8">
    161. <spacer name="horizontalSpacer">
    162. <property name="orientation">
    163. <enum>Qt::Horizontal</enum>
    164. </property>
    165. <property name="sizeHint" stdset="0">
    166. <size>
    167. <width>40</width>
    168. <height>20</height>
    169. </size>
    170. </property>
    171. </spacer>
    172. </item>
    173. <item row="1" column="7">
    174. <widget class="QPushButton" name="File_Name_Browse">
    175. <property name="text">
    176. <string>Browse</string>
    177. </property>
    178. </widget>
    179. </item>
    180. <item row="1" column="0" colspan="7">
    181. <widget class="QLineEdit" name="File_Name_Box"/>
    182. </item>
    183. <item row="5" column="0" colspan="8">
    184. <layout class="QHBoxLayout" name="horizontalLayout">
    185. <item>
    186. <spacer name="horizontalSpacer_2">
    187. <property name="orientation">
    188. <enum>Qt::Horizontal</enum>
    189. </property>
    190. <property name="sizeHint" stdset="0">
    191. <size>
    192. <width>40</width>
    193. <height>20</height>
    194. </size>
    195. </property>
    196. </spacer>
    197. </item>
    198. <item>
    199. <widget class="QPushButton" name="Dummy_button">
    200. <property name="text">
    201. <string>Dummy</string>
    202. </property>
    203. </widget>
    204. </item>
    205. <item>
    206. <spacer name="horizontalSpacer_3">
    207. <property name="orientation">
    208. <enum>Qt::Horizontal</enum>
    209. </property>
    210. <property name="sizeHint" stdset="0">
    211. <size>
    212. <width>40</width>
    213. <height>20</height>
    214. </size>
    215. </property>
    216. </spacer>
    217. </item>
    218. <item>
    219. <widget class="QPushButton" name="Bathy_Import_Button">
    220. <property name="text">
    221. <string>Import</string>
    222. </property>
    223. </widget>
    224. </item>
    225. <item>
    226. <spacer name="horizontalSpacer_4">
    227. <property name="orientation">
    228. <enum>Qt::Horizontal</enum>
    229. </property>
    230. <property name="sizeHint" stdset="0">
    231. <size>
    232. <width>40</width>
    233. <height>20</height>
    234. </size>
    235. </property>
    236. </spacer>
    237. </item>
    238. </layout>
    239. </item>
    240. <item row="0" column="0" colspan="3">
    241. <widget class="QLabel" name="label">
    242. <property name="text">
    243. <string>Select File</string>
    244. </property>
    245. </widget>
    246. </item>
    247. </layout>
    248. </item>
    249. </layout>
    250. </widget>
    251. <tabstops>
    252. <tabstop>File_Name_Box</tabstop>
    253. <tabstop>File_Name_Browse</tabstop>
    254. <tabstop>Comma_radioButton_2</tabstop>
    255. <tabstop>TAB_radioButton</tabstop>
    256. <tabstop>SPACE_radioButton_3</tabstop>
    257. <tabstop>Other_radioButton_4</tabstop>
    258. <tabstop>Delimeter_text</tabstop>
    259. <tabstop>Combo_X</tabstop>
    260. <tabstop>Combo_Y</tabstop>
    261. <tabstop>Combo_Z</tabstop>
    262. <tabstop>SkipRows</tabstop>
    263. <tabstop>tableView</tabstop>
    264. <tabstop>Dummy_button</tabstop>
    265. <tabstop>Bathy_Import_Button</tabstop>
    266. <tabstop>graphicsView</tabstop>
    267. </tabstops>
    268. <resources/>
    269. <connections/>
    270. </ui>
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 25th February 2021 at 18:27.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. The following user says thank you to d_stranz for this useful post:

    Zoner (4th March 2021)

  7. #5
    Join Date
    Feb 2021
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt5
    Platforms
    Windows

    Default Re: Qtableview margin/padding

    I watched some vids yesterday, not sure why I didn't do it before. I guess I was code obsessed.
    Thank you very much for the code example, I will have a good look over the weekend.
    Again, really appreciate it. I chose quite a complicated python project to emerge myself, so need all the help (and time) I can get.

  8. #6
    Join Date
    Feb 2021
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt5
    Platforms
    Windows

    Default Re: Qtableview margin/padding

    This was very helpful. I was able to change my previous design, since I like doing things the hard way.
    I do need to research your example a bit more, since I think I might have missed some expert features.
    May I bother you for one more question.
    Its similar to the tableview problem.
    I want to connect my pyvistacode to graphicsView (or the likes) based on the .ui you altered
    I can make it work, but I seem to overwrite the graphicsView with a new window.


    Qt Code:
    1. #required imports
    2.  
    3. import pyvista as pv
    4. import pyvistaqt
    5. from pyvistaqt import *
    6.  
    7. #setting printer (creating double widget!)
    8. self.plt = pyvistaqt.QtInteractor(self.graphicsView)
    9.  
    10. self.add_box()
    11. def add_box(self):
    12. box = pv.Box()
    13. self.plt.add_mesh(box)
    14. self.plt.reset_camera()
    15. self.plt.fly_to_mouse_position()
    16. self.plt.show()
    To copy to clipboard, switch view to plain text mode 

    I've read somewhere that the object name can already be considered as the plotter.
    what I dont seem to grasp is:
    1. am I using the right Widget
    2. If so, how do I connect it

  9. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,884
    Thanks
    274
    Thanked 794 Times in 784 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qtableview margin/padding

    I'm afraid I don't know anything about pyvistaqt. But line 8 -is- creating a new pyvistaqt QtInteractor object with your graphicsView object as its parent and assigning the reference to self.plt. If you have already created a QtInteractor and assigned it to self.plt, then this line of code is wrong.

    You seem to be a bit confused about how to retrieve an object reference from somewhere and creating a new one. Because your code is creating new instances, you are going to end up with overlapping widgets (and orphans, because if self.plt was already assigned elsewhere, when you reassign it you have no way to retrieve the previous reference). But because you also create them with parents, the widgets don't go away until the parents themselves are deleted. So you end up with overlapped widgets.

    how do I connect it
    I am not really sure what you mean by "connect". I think you mean to say, "retrieve the reference to it" because in Qt, connect() has a very specific meaning in terms of signal-slot "connections".

    If you haven't seen it already, there is an example of using a QtInteractor here.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. #8
    Join Date
    Feb 2021
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt5
    Platforms
    Windows

    Default Re: Qtableview margin/padding

    Yeah I do struggle a bit. I was integrating with qinteractor, but I think it also has to do with widget compatibility. I can get the whole thing going in a frame widget, but not in a graphic widget. I'm rejigging all the code now to simplify it, then I can probably oversee everything a bit better.

    Thanks for your reply

  11. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,884
    Thanks
    274
    Thanked 794 Times in 784 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qtableview margin/padding

    Thanks for turning me on to pyvista and pyvistaqt. I use a little bit of VTK in my C++ applications and it is nice to know there is a way to use it from Python as well.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  12. #10
    Join Date
    Feb 2021
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt5
    Platforms
    Windows

    Default Re: Qtableview margin/padding

    ha

    Glad I could help for once! Their example projects are a big motivator, absolutely stunning.

Similar Threads

  1. Qtableview margin/padding
    By Zoner in forum Newbie
    Replies: 1
    Last Post: 24th February 2021, 17:08
  2. QListWidget margin/padding space
    By Hennessy in forum Newbie
    Replies: 0
    Last Post: 28th March 2014, 15:01
  3. QTabWidget icon padding/margin?
    By Nyte in forum Newbie
    Replies: 0
    Last Post: 2nd April 2013, 11:31
  4. Replies: 3
    Last Post: 25th June 2010, 05:21
  5. QPainter.drawText and margin/padding
    By invictus in forum Newbie
    Replies: 1
    Last Post: 24th July 2009, 12:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.