qt - How do I resize QTableView so that the area is not scrolled anymore -


I want to keep the size of QTableView equal to that table (and default) so that it is not a scrollbar

What you can do is calculate your table view column width according to their data (or you can change the size of each column Can call up to column-to-continents for size on their content). Then, if the width of the tableview is equal to equal or greater then change the total width of the column + vertical headers if shown. If you have been shown the horizontal header then you will need to track the model changes and adjust your table view width, you can resize the columns and adjust them again, there is some sample code for this below: / P>

Initialization:

  // Add 3 columns in the table view control table-> Insert column (0, QModelIndex ()); Table modal-> Insert column (1, qmdale index ()); Table modal-> Insert column (2, qmdale index ()); ... // Close horizontal scrollbar; Although it is not really needed here, Iui- gt; TableView-> Set Horizontal ScrollBarPolicy (Qt :: ScrollBarAlwaysOff); // adjusted size; See the code below the adjustment (); // Connect horizontal header resize event (header is not shown if it is not needed) Connect (ui- & gt; Table view-> horizontal header), signal (section rhesis (int, int, int)), This, SLOT (updateSectionWidth integer, integer, integer))); // Connect to the data exchange event of the model (ui- & gt; Table view- & gt; Model ()), signal (data changelief (qmdell index, qmdel index)), this slot (data changed (qmdel index, qmdel Indexes));  

Adjust the table view size:

  zero main window :: adjustable size () {ui-> Table view- & gt; Change shape CollumnToContents (0); UI- & gt; TableView-> ResizeColumnToContents (1); UI- & gt; TableView-> ResizeColumnToContents (2); QRect rect = ui- & gt; Table view- & gt; Geometry (); Rect.setWidth (2 + ui- & gt; Table View- & gt; Vertical Header () - & gt; Width () + ui- & gt; Table View- & gt; Column Width (0) + ui- & gt; ; Table view- & gt; column width (1) + UI-> TableView-> columnWidth (2)); UI- & gt; TableView-> SetGeometry (Rect); }  

Process model change

  Zero main window :: Data changelog (Const. Qmdell index and top left, consume cumdel indices and oakright) {adjusting Deserving (); }  

Change the shape of the horizontal header

  zero MainWindow :: updateSectionWidth (int logical indices, int, int newSize) {adjustTableSize (); }  

Hope this helps,


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -