Results 1 to 12 of 12

Thread: Looking for list-widget like string stack class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Looking for list-widget like string stack class

    Or may be you can look at QListWidget

  2. #2
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Looking for list-widget like string stack class

    Quote Originally Posted by aamer4yu View Post
    Or may be you can look at QListWidget
    As I wrote im my second post in this thread I know listwidget very well but expect not really a very good speed if I constantly remove the first item and add a new last one and that every second.

  3. #3
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Looking for list-widget like string stack class

    My solution using the ideas posted here looks now like this:
    Qt Code:
    1. #include "ui/ui_WidgetListStringStack.h"
    2. #include <QtCore/QStringList>
    3. #include <QtGui/QStringListModel>
    4. #include <QtCore/QPointer>
    5.  
    6. class WidgetListStringStack : public QWidget, protected Ui_WidgetListStringStack
    7. {
    8. Q_OBJECT
    9. public:
    10. WidgetListStringStack(QWidget* parent = 0, Qt::WFlags flags = 0);
    11. virtual ~WidgetListStringStack();
    12.  
    13. private:
    14. QPointer<QStringListModel> StringListModel;
    15. QStringList StackList;
    16. int MaxStackSize;
    17.  
    18. public:
    19. void addMessage(QString & message);
    20. void setMaxStackSize(int value);
    21.  
    22. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. WidgetListStringStack::WidgetListStringStack( QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/ ) : QWidget(parent, flags)
    2. {
    3. setupUi(this);
    4. setMaxStackSize(100);
    5. StringListModel=new QStringListModel();
    6. }
    7.  
    8.  
    9. WidgetListStringStack::~WidgetListStringStack()
    10. {
    11. }
    12.  
    13. void WidgetListStringStack::setMaxStackSize(int value)
    14. {
    15. MaxStackSize = value;
    16. }
    17.  
    18. void WidgetListStringStack::addMessage(QString & message)
    19. {
    20. StackList.append(message);
    21. if (StackList.size() > MaxStackSize)
    22. StackList.removeFirst();
    23.  
    24. StringListModel->setStringList(StackList);
    25.  
    26. listView->setModel(StringListModel);
    27. }
    To copy to clipboard, switch view to plain text mode 

    I filled it using a timer with 100ms and it does not flicker and looks very smooth.

    However I need to look at the last item by default. How do I reset the view at every addMessage() call ?

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

    Default Re: Looking for list-widget like string stack class

    What do you mean by reset? You wish to scroll the view to the end? Just take a look at QAbstractItemView docs and you'll see.

    Anyway, I'd rather use a simple model with a circular buffer with a regular QListView.

Similar Threads

  1. MVC - Abstract Widget Base Class - setupUI
    By SenSej in forum Newbie
    Replies: 0
    Last Post: 13th October 2008, 11:44
  2. Replies: 1
    Last Post: 7th August 2007, 09:27
  3. QWidget display on 2 stack widget page
    By spawnwj in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2006, 13:07

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
  •  
Qt is a trademark of The Qt Company.