Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove scrollbar to show full table

I have a scrollview to which I dynamically add QTableWidgets. However, the QTables themselves also have scrollbars and therefore don't show the full table. Is there a way to disable the scroll bar so that the table always gets shown in full?

enter image description here

EDIT: I added

    self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
    self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

As suggested. The scroll bar does disappear, but it still only shows the partial tables (Ican scroll with hovering iverthe table and using the mouse wheel, still). The code for the Widget is below

from PySide.QtGui import *
from PySide.QtCore import *

class MdTable(QTableWidget):
    def __init__(self, data, depth, *args):

        QTableWidget.__init__(self, *args)
        self.hheaders = ["c1", "c2", "c3", "c4"]
        self.depth = depth
        self.bids = data
        self.setData()

    def setData(self):

        self.setRowCount(self.depth)
        self.setColumnCount(5)

        for i in xrange(self.depth):
            if len(self.data) > i:
                d1= QTableWidgetItem(str(self.data[i][0]))
                d2= QTableWidgetItem(str(self.data[i][1]))
                self.setItem(i, 1, d1)
                self.setItem(i, 2, d2)

        self.setHorizontalHeaderLabels(self.hheaders)
        self.verticalHeader().setVisible(False)
        self.resizeRowsToContents()
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
like image 674
chrise Avatar asked Jan 09 '17 07:01

chrise


People also ask

How do I get rid of the vertical scroll bar on my table?

You can remove this scroll bar by setting the HasScrollBar attribute of the TableField object to FALSE. The syntax for this operation is: field(tablefield).

How do I get rid of the extra scroll bar?

You can first try selecting the scroll bar by using a right click and then once selected you can press delete but you may need to first put the sheet into 'Design Mode' (see the option under the Developer menu in the above image). Once in Design mode you should be able to select the scroll bar and hit delete.

How do I hide horizontal scrollbar but still scroll?

The second fiddle only scrolls horizontally, you can hold shift and then use mouse scroll to go left and right. I have also tested this in chrome and it works fine for me.

How do I stop scrolling without scrollbar hiding?

Disabling scroll with only CSS. There's another way to disable scrolling that is commonly used when opening modals or scrollable floating elements. And it is simply by adding the CSS property overflow: hidden; on the element you want to prevent the scroll.

How do I make my scrollbar only appear when overflow?

Use overflow: auto . Scrollbars will only appear when needed. (Sidenote, you can also specify for only the x, or y scrollbar: overflow-x: auto and overflow-y: auto ).

How do I get rid of the horizontal scroll bar in Excel?

Click the File tab. Click Options, and then click the Advanced category. Under Display options for this workbook, clear or select the Show horizontal scroll bar check box and Show vertical scroll bar check box to hide or display the scroll bars.


1 Answers

If you just want to delete the Scrollbar you must use:

{QtableWidget}.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
{QtableWidget}.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

If you want to show the expanded QTableWidget, add this to the end of the setData() method:

self.setMaximumSize(self.getQTableWidgetSize())
self.setMinimumSize(self.getQTableWidgetSize())

and define getQTableWidgetSize(self) like this:

def getQTableWidgetSize(self):
    w = self.verticalHeader().width() + 4  # +4 seems to be needed
    for i in range(self.columnCount()):
        w += self.columnWidth(i)  # seems to include gridline (on my machine)
    h = self.horizontalHeader().height() + 4
    for i in range(self.rowCount()):
        h += self.rowHeight(i)
    return QtCore.QSize(w, h)

enter image description here

Note: The function getQTableWidgetSize is a conversion of the code in C ++ to python of the following post: How to determine the correct size of a QTableWidget?

like image 129
eyllanesc Avatar answered Oct 05 '22 02:10

eyllanesc