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
Forum Updated to NodeBB v4.3 + New Features

Custom list widget

Scheduled Pinned Locked Moved General and Desktop
customwidgetlist
6 Posts 3 Posters 4.6k Views 2 Watching
  • 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.
  • Robey MardonR Offline
    Robey MardonR Offline
    Robey Mardon
    wrote on 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.

    p3c0P 1 Reply Last reply
    0
    • Robey MardonR Robey Mardon

      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.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on 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

      Robey MardonR 1 Reply Last reply
      2
      • p3c0P p3c0

        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 .

        Robey MardonR Offline
        Robey MardonR Offline
        Robey Mardon
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stephane78
          wrote on 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.

          p3c0P 1 Reply Last reply
          1
          • S stephane78

            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.

            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on 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 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

              • Login

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