Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Custom list widget
QtWS25 Last Chance

Custom list widget

Scheduled Pinned Locked Moved General and Desktop
customwidgetlist
6 Posts 3 Posters 4.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robey Mardon
    wrote on 30 Apr 2015, 12:37 last edited by
    #1

    Hi there, I'd like to know how to create a custom list widget like this:

    Image 1
    Image 2
    Image 3

    All of them has an image, buttons and informations, how can I do a custom widget like that?

    Thanks in advance.

    P 1 Reply Last reply 30 Apr 2015, 12:59
    0
    • R Robey Mardon
      30 Apr 2015, 12:37

      Hi there, I'd like to know how to create a custom list widget like this:

      Image 1
      Image 2
      Image 3

      All of them has an image, buttons and informations, how can I do a custom widget like that?

      Thanks in advance.

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 30 Apr 2015, 12:59 last edited by
      #2

      Hi @Robey-Mardon and Welcome,
      With that amount of customization its better to go with QListView with custom delegate. You can use QStyledItemDelegate and reimplement paint method to draw text or pixmaps using QPainter's drawText and drawPixmap. Explore more functions for QPainter.
      Now to draw controls like buttons and progressbar use classes like QStyleOptionButton and QStyleOptionProgressBar inherited from QStyleOption.

      More about Model/View Programming in Qt is here .

      157

      R 1 Reply Last reply 30 Apr 2015, 13:02
      2
      • P p3c0
        30 Apr 2015, 12:59

        Hi @Robey-Mardon and Welcome,
        With that amount of customization its better to go with QListView with custom delegate. You can use QStyledItemDelegate and reimplement paint method to draw text or pixmaps using QPainter's drawText and drawPixmap. Explore more functions for QPainter.
        Now to draw controls like buttons and progressbar use classes like QStyleOptionButton and QStyleOptionProgressBar inherited from QStyleOption.

        More about Model/View Programming in Qt is here .

        R Offline
        R Offline
        Robey Mardon
        wrote on 30 Apr 2015, 13:02 last edited by
        #3

        @p3c0 Thank you, I'll be reading that.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stephane78
          wrote on 5 May 2015, 15:08 last edited by
          #4

          Hi,
          I have another perhaps easyer solution that I have already used in one software. You use a QTableWidget with one column instead of a QListWidget, and you create a class that derivate from QTableWidgetItem and of Qwidget :

          #define     WType      ((QTableWidgetItem::UserType)+200)
          
          class TableWidgetItem : public QTableWidgetItem,public QWidget
          {
          public:
              TableWidgetItem(QWidget * parent = 0, Qt::WindowFlags f = 0,int type=WType);
            ...
          

          as this class derivate from Qwidget you can add what you want in this class..it runs well.and you insert objects of this class in you QTablewidget.

          P 1 Reply Last reply 6 May 2015, 06:44
          1
          • S stephane78
            5 May 2015, 15:08

            Hi,
            I have another perhaps easyer solution that I have already used in one software. You use a QTableWidget with one column instead of a QListWidget, and you create a class that derivate from QTableWidgetItem and of Qwidget :

            #define     WType      ((QTableWidgetItem::UserType)+200)
            
            class TableWidgetItem : public QTableWidgetItem,public QWidget
            {
            public:
                TableWidgetItem(QWidget * parent = 0, Qt::WindowFlags f = 0,int type=WType);
              ...
            

            as this class derivate from Qwidget you can add what you want in this class..it runs well.and you insert objects of this class in you QTablewidget.

            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 6 May 2015, 06:44 last edited by
            #5

            @stephane78 Well in that case why QTableWidget and QTableWidgetItem ? Use QListWidget and QListWidgetItem. Using custom delegates for large customization is more flexible.

            157

            1 Reply Last reply
            0
            • S Offline
              S Offline
              stephane78
              wrote on 6 May 2015, 14:17 last edited by
              #6

              @p3c0
              you are right it's better to use custom delegates like you say.
              I am not sure my solution runs with QListWidget but it is ok too with QTablewidget.

              1 Reply Last reply
              0

              4/6

              5 May 2015, 15:08

              • Login

              • Login or register to search.
              4 out of 6
              • First post
                4/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved