Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 03-07-2011, 12:30 PM   #1
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
Resizing tables in window

I'm using a table inside a window, and the width of the columns/table just isn't what I want it to be especially on resizing - I get space on the right of the table, e.g.

w = QWidget()
layout = QVBoxLayout(w)
w.setLayout(layout)
....
table_layout = QHBoxLayout()
layout.addLayout(table_layout)

table = ConfigTableWidget(w)
table_layout.addWidget(table)

I can set the default size of the window. I can resize the columns to match their contents. But I haven't figured out how to resize the table to fill the layout completely - preferably by expanding one or two of the columns to a larger size and not the others. I'd even like to calculate the default width of the window based on either a maximum size or the width of the table, but anything that gets it to look a bit better would help.

Any suggestions?
meme is offline   Reply With Quote
Old 03-07-2011, 01:11 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,811
Karma: 5006091
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Look at the QHeaderView, it should allow you to do most of what you want.
kovidgoyal is offline   Reply With Quote
 
Enthusiast
Old 03-08-2011, 12:06 PM   #3
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
That got me closer, but I'm still not quite there. I can get the table to resize so the last column expands (and even one of the columns in the middle) so the table fills the space. But the column widths don't stay as I want them.

Below is example code - just run it under python and it will create a very simple table. If you drag to resize it you will see that the table expands to fill the window by making the last column larger. BUT if you shrink the table you will see that the width of the last column becomes smaller than either the header or the column data, which is not what I want. I'd like it to never get smaller than the width of the header/data - forcing a scrollbar to appear just like it does for the other columns. Clearly there must be a setting to tell it to allow a column to get bigger to fill the space, but not smaller than it started with.


Code:
import sys
from PyQt4.Qt import Qt, QWidget, QVBoxLayout, QApplication, QTableWidget, QTableWidgetItem, QDialog

class TableWidget(QTableWidget):
    def __init__(self, *args):
        QTableWidget.__init__(self, *args)
        self.setRowCount(1)
        self.setColumnCount(4)

        self.setItem(0, 0, QTableWidgetItem('Short'))
        self.setItem(0, 1, QTableWidgetItem('Short'))
        self.setItem(0, 2, QTableWidgetItem('Test very long entry in the box to see what happens to this one'))
        self.setItem(0, 3, QTableWidgetItem('Test very long entry in the box to see what happens to this one'))

        self.setHorizontalHeaderLabels(['A', 'Test of a long header but a short entry column', 'B', 'Test of a long header and a long entry column' ])

        h = self.horizontalHeader()
        h.setStretchLastSection(True)
        self.resizeColumnsToContents()

def table():

    w = QWidget()
    layout = QVBoxLayout(w)
    w.setLayout(layout)

    table = TableWidget(w)
    layout.addWidget(table)
    return w

app = QApplication(sys.argv)
dialog = QDialog()
v = QVBoxLayout(dialog)
v.addWidget(table())

dialog.exec_()
meme is offline   Reply With Quote
Old 03-08-2011, 12:47 PM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,811
Karma: 5006091
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
minimumsectionsize
kovidgoyal is offline   Reply With Quote
Old 03-08-2011, 01:17 PM   #5
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
Yeah, I've tried setMinimumSectionSize. Unfortunately it sets the minimum size for all the header columns so columns that should be narrow have to be as wide as the widest column. Unlike setResizeSection there doesn't seem to be a way to set a minimum for just a column.
meme is offline   Reply With Quote
Old 03-08-2011, 01:27 PM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,811
Karma: 5006091
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
The only other alternative is to set resizemode to autoresize

And finally, write your own delegate that implements sizeHint the way you want.
kovidgoyal is offline   Reply With Quote
Old 03-09-2011, 10:00 AM   #7
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
I've tried the delegate approach but just can't get it to work. If I set Stretch mode, then sizeHint doesn't get called, and if I don't set it, it doesn't stretch. I've tried using paint which is getting called, but can't get the column to resize.

I've even tried turning it around and fixing the maximum size of the window so that it doesn't grow larger than the table, but dropped it after a bit for being too fiddly.

At this point I'm leaving things as they are. I see the main Calibre library doesn't worry about the extra space on the right of the table either. For another table, due to the contents of the columns/headers I can set a minimum section size and table re-sizing works great. I may in fact apply that to the first table one more time to see if it works ok.

Thanks for the pointers.
meme is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Image resizing Falcao Feedback 7 10-28-2010 04:32 AM
Epub resizing problem edbro Calibre 2 08-30-2010 09:31 PM
Resizing window on 1024x600 netbook tom95521 Calibre 6 08-13-2009 12:30 PM
any better ideas ? (image resizing) zelda_pinwheel IMP 20 03-30-2008 01:10 AM
Software for resizing PDF's tshare Sony Reader 9 02-07-2007 11:39 AM


All times are GMT -4. The time now is 09:57 PM.


MobileRead.com is a privately owned, operated and funded community.