Results 1 to 2 of 2

Thread: How to make and use custom UI widgets for a list

  1. #1
    Join Date
    May 2014
    Qt products

    Default How to make and use custom UI widgets for a list

    Hi all,

    I’m doing a apprenticeship to a Software Developer, so my Know-How is pretty low (also my english, sorry for any mistakes)

    I’m currently working on a book libary and i used a QTableWidget to show all books (including image, title, author and a short discription). At this point i fill in every single cell with an QTableWidgetItem, to show a single Information.

    Now my instruktor wants me, to write a single UI class that represents a book with all given information, which then I can insert my Table/List. But here comes my problem: I can’t find a good tutorial or even the right keywords.

    What I know so far: I think I need to write the UI class (name it BookView) thats need to be a QWidget. Then I could insert this BookView in my Table/List. But I dont have the knowledge, Maybe I’m searching with the wrong keywords.

    I'm using Qt 5 with C++.

    Any help will be appreciated.

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 803 Times in 792 Posts
    Qt products
    Windows Android

    Default Re: How to make and use custom UI widgets for a list

    You need to derive your BookView from QWidget. Use Qt Designer to design the widget - that's easiest. You will probably want to start with a grid or form layout, and add QLabel items that will hold the book image, title, and other strings.

    At run time, when you read your list of books, you'll create a BookView widget instance for each book, and set the image on the BookView instance's imageLabel, the title string as the text on titleLabel, and so on. You can then install that in the table widget using QTableWidget::setCellWidget() method. After you are done inserting everything, you'll probably want to call resizeRowsToContents() and resisizeColumnsToContent() on the table widget.

Similar Threads

  1. Replies: 0
    Last Post: 30th April 2012, 15:17
  2. Replies: 2
    Last Post: 20th August 2010, 13:20
  3. Populating a QtableWidget using a list of custom widgets
    By gerocampo in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2010, 10:28
  4. How to build a list of custom widgets
    By curreli in forum Newbie
    Replies: 6
    Last Post: 28th July 2010, 12:55
  5. Replies: 0
    Last Post: 15th May 2009, 15:38


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.