Results 1 to 7 of 7

Thread: Dynamic number of rows and columns with QTableWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic number of rows and columns with QTableWidget

    Quote Originally Posted by wysota
    There is resizeEvent() which you can override (either by an event filter or by subclassing). This is also a solution to your first problem. A resize event is triggered right after the widget is shown (or rather "assigned size").
    I've tried to subclass it, unfortunately when calling tableWidget->height() from resizeEvent(), it still reports the wrong size. However, as soon as i resize the window, the reported size is correct. It is a bit frustrating that it doesn't work at the first resizeEvent() call.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic number of rows and columns with QTableWidget

    Quote Originally Posted by Med
    I've tried to subclass it, unfortunately when calling tableWidget->height() from resizeEvent(), it still reports the wrong size. However, as soon as i resize the window, the reported size is correct. It is a bit frustrating that it doesn't work at the first resizeEvent() call.
    You should use values given by QResizeEvent:

    Qt Code:
    1. MyWidget::resizeEvent(QResizeEvent *e){
    2. qDebug("New size is: %d x %d", e->size().width(), e->size().height());
    3. QWidget::resizeEvent(e);
    4. }
    To copy to clipboard, switch view to plain text mode 

    On the other hand the docs say the widget already has it's new size set...

    You could also try showEvent().
    Last edited by wysota; 5th March 2006 at 19:42.

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

    Med (5th March 2006)

  4. #3
    Join Date
    Mar 2006
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic number of rows and columns with QTableWidget

    Quote Originally Posted by wysota
    On the other hand the docs say the widget already has it's new size set...

    You could also try showEvent().
    Thank you very much! In fact using resizeEvent(), the size of the window was correctly reported while the size of the tableWidget wasn't. However using showEvent() as you suggested, the widget size was correctly reported. I guess the widget size is actually set after the resizeEvent() and before the showEvent(). Now i can continue toying with Qt.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic number of rows and columns with QTableWidget

    Maybe you overrode resizeEvent or the wrong widget?

Similar Threads

  1. QTableWidget: Disable 'snapping' to rows and columns?
    By PolyVox in forum Qt Programming
    Replies: 2
    Last Post: 8th October 2008, 20:04

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.