Results 1 to 17 of 17

Thread: Adding items to QlistWidget or QtableWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Adding items to QlistWidget or QtableWidget

    In my quest to create something like this: https://vimeo.com/110260781

    I have an object, a boxLayout, with a few widgets inside- a label, that acts as a image player, a label that shows the frame count, and a slider. I have interactivity setup just like the video where I have mouse over events and timeline start and stop functions.

    First of, which should I use? QlistWidget or QtableWidget? or is there something more appropriate for this case?

    secondly, how would I go about implementing something like this? How do I add my template/boxLayout to each cell of the table.

    Thank You!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Adding items to QlistWidget or QtableWidget

    As a first try I would go for a QGridLayout on a widget in a QScrollArea.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding items to QlistWidget or QtableWidget

    So this is what I have. I'm trying your last comment Anda, but I'm doing something wrong.
    I have a few labels, which I put inside a QGridLayout, and then I'm trying to put it into the scroll area, but I'm getting an error on line 34
    The Error says
    TypeError: scrollArea.setWidget(QWidget) : argument 1 has unexpected type (QGridLayout)
    Qt Code:
    1. class ViewerLabel(QLabel):
    2. def __init__(self, parent=None):
    3. super(ViewerLabel, self).__init__(parent)
    4. self.setMouseTracking(True)
    5. self.setAlignment(Qt.AlignCenter)
    6.  
    7. def enterEvent(self,event):
    8. button.setStyleSheet("background-color:#45b545;")
    9.  
    10. def leaveEvent(self,event):
    11. button.setStyleSheet("background-color:yellow;")
    12.  
    13. def main():
    14.  
    15. layout = QGridLayout()
    16. scrollArea = QScrollArea()
    17.  
    18. label_01 = ViewerLabel(“label 01”)
    19. label_02 = ViewerLabel(“label 02”)
    20. label_03 = ViewerLabel(“label 03”)
    21. label_04 = ViewerLabel(“label 04”)
    22. label_05 = ViewerLabel(“label 05”)
    23. label_06 = ViewerLabel(“label 06”)
    24.  
    25. layout.addwidget(label_01, 0, 1)
    26. layout.addwidget(label_02, 0, 2)
    27. layout.addwidget(label_03, 1, 1)
    28. layout.addwidget(label_04, 1, 2)
    29. layout.addwidget(label_05, 2, 1)
    30. layout.addwidget(label_06, 2, 2)
    31.  
    32. layout.setSpacing(10)
    33.  
    34. scrollArea.setWidget(layout)
    35. window.setLayout(scrollArea)
    36.  
    37. window.setFixedSize(400,500)
    38. window.show()
    39.  
    40. return app.exec_()
    41.  
    42.  
    43. if __name__ == __main__:
    44. main()
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Adding items to QlistWidget or QtableWidget

    "layout" is not a QWidget, QScrollArea::setWidget expects one.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding items to QlistWidget or QtableWidget

    Right! I should have know that! Haha. So I need to use .setLayout instead of .setWidget.

    Thanks Again!
    Last edited by Nfrancisj; 9th May 2016 at 17:15.

  6. #6
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding items to QlistWidget or QtableWidget

    Nope...well that didn't work for me either. Now I get an error on window.setLayout because that's expecting a layout, not widget.

    So how do I do this? How do I get a GridLayout to work with ScrollArea. I also tried this in the designer, and it kinda didn't work either. I added the scroll to the form, buttons inside the scroll, and set the scroll to GridLayout. The scroll did size with the window, but the scroll bars didn't appear.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Adding items to QlistWidget or QtableWidget

    Quote Originally Posted by Nfrancisj View Post
    Right! I should have know that! Haha. So I need to use .setLayout instead of .setWidget.
    No.

    setWidget() is correct, it sets the content widget of the scrollarea.
    setLayout() would change the layout of the scrollarea, you definitely don't want that.

    As I said in my initial reply, add a widget to the scroll area, put the buttons onto that widget using an appropriate layout.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 20th June 2013, 06:24
  2. QListWidget, help adding new items.
    By JeremyRussell in forum Newbie
    Replies: 4
    Last Post: 6th April 2011, 23:54
  3. Replies: 1
    Last Post: 22nd February 2010, 10:53
  4. adding items in qtablewidget
    By Djony in forum Qt Programming
    Replies: 17
    Last Post: 24th November 2006, 10:03
  5. [Qt4]: Adding centered items in QListWidget
    By Jojo in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2006, 20:04

Tags for this Thread

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.