Results 1 to 9 of 9

Thread: QListWidget refreshing issue

  1. #1
    Join Date
    Feb 2010
    Posts
    61
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    18

    Default QListWidget refreshing issue

    Hi,

    I have QListWidget within a QGroupBox and I would like the group box title to display the number of items of QListWidget. So I wrote the following the function:

    Qt Code:
    1. void Test::add(const QString& item) {
    2. listWidget->addItem(item); // adds item to QListWidget
    3. groupBox->setTitle("Currently (" + QString::number(listWidget->count()) + ")"); // updates QGroupBox title
    4. }
    To copy to clipboard, switch view to plain text mode 

    Unfortunately when add is called, no modification appears on the QListWidget even though the title is updated immediately. listWidget is refreshed when one clicks on it... This is annoying since I need a real-time update.

    I tried to perform a workaround by calling one of the functions below right after setTitle:
    Qt Code:
    1. listWidget->update();
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QCoreApplication::processEvents();
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    but all my attempts failed.

    What could I do next ?

  2. #2
    Join Date
    May 2010
    Posts
    61
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    2
    Thanked 6 Times in 5 Posts

    Default Re: QListWidget refreshing issue

    Hi ouekah,

    Find attached to this reply a small project that I created to test your scneraio. In my case, it works. Maybe it has to to with the fact the I've been using Qt Designer mode to create the ui.

    Anyway, maybe this project will help you identifying your problem.

    Regards,
    Wladek
    Attached Files Attached Files

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: QListWidget refreshing issue

    This should be done automatically.
    My guess is that you have overridden the Test::paintEvent(), or somewhere else in the widget hierarchy.
    Try this:
    Qt Code:
    1. void Test::add(const QString& item) {
    2. listWidget->addItem(item); // adds item to QListWidget
    3. groupBox->setTitle("Currently (" + QString::number(listWidget->count()) + ")"); // updates QGroupBox title
    4. update();
    5. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. The following user says thank you to high_flyer for this useful post:

    ouekah (8th July 2010)

  5. #4
    Join Date
    Feb 2010
    Posts
    61
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    18

    Default Re: QListWidget refreshing issue

    @wladek: thanks a lot for your example ! Unfortunately I have the same problem with your program...

    When you add the items to the listWidget, the count is updated immediately but not the listWidget's content.. I need to click on the listWidget to actually see the updated content.

    I start to wonder if the problem lies with something else like my operating system or the way I compile the project... This is really weird...

    I'm using OS X 10.6.3 and I compiled your example in two steps:

    1) qmake -spec macx-g++
    2) make

    I have attached four screenshots, so you can see by your self what happens...

    @high_flyer: I tried the update(), but doesn't work...
    Attached Files Attached Files

  6. #5
    Join Date
    May 2010
    Posts
    61
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    2
    Thanked 6 Times in 5 Posts

    Default Re: QListWidget refreshing issue

    I have some MACs around here in the office. Let me just test this example on them and let you know the result.
    This is becoming very interesting (and I am sure annoying for you).

    Wladek.
    One second is long, everything longer than two seconds is definitely too long.

  7. #6
    Join Date
    May 2010
    Posts
    61
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    2
    Thanked 6 Times in 5 Posts

    Default Re: QListWidget refreshing issue

    My testing on MAC OS X version 10.5.8 (Snow) gave the same results like yours.
    This seems to be a Qt issue. Could this be a possible bug in the framework?

    I don't know what to suggest for making this work.
    If you find something, please let me also know.

    Regards,
    Wladek

  8. The following user says thank you to wladek for this useful post:

    ouekah (8th July 2010)

  9. #7
    Join Date
    Feb 2010
    Posts
    61
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    18

    Default Re: QListWidget refreshing issue

    I tried almost everything I guess... I will just the remove the "count" functionality (it works fine if the program does not update the groupBox title all the time...).

    That's a shame. Is there any way to forward this issue to Qt ?

    Thanks again for your support !
    Best regards,

    ouekah

  10. #8
    Join Date
    May 2010
    Posts
    61
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    2
    Thanked 6 Times in 5 Posts

    Default Re: QListWidget refreshing issue

    Hey ouekah,

    Good news! I believe i have found a hack for solving this.
    I just had an idea and tried it out on my Mac. What I did was the following:
    1. added a private slot in my header
    Qt Code:
    1. private slots:
    2. void buttonWasPushed();
    3. void updateGroupBoxTitle();
    To copy to clipboard, switch view to plain text mode 

    2. In the already defined add function I do not call directly groupBox->setTitle(), but instead I use the QTimer:singleShot() static function:
    Qt Code:
    1. void Form::add(const QString& item)
    2. {
    3. ui->listWidget->addItem(item);
    4. QTimer::singleShot(0, this, SLOT(updateGroupBoxTitle()));
    5. }
    To copy to clipboard, switch view to plain text mode 
    .

    Then, in the implementation of the updateGroupBoxTitle() slot i just set the title of the groupbox:
    Qt Code:
    1. void Form::updateGroupBoxTitle()
    2. {
    3. ui->groupBox->setTitle("Currently (" + QString::number(ui->listWidget->count()) + ")"); // updates QGroupBox title
    4. }
    To copy to clipboard, switch view to plain text mode 

    This works for me. I hope it will be functional for you also.
    If it does work, do not ask me why .

    Waiting for your feedback...
    Wladek
    One second is long, everything longer than two seconds is definitely too long.

  11. The following user says thank you to wladek for this useful post:

    ouekah (8th July 2010)

  12. #9
    Join Date
    Feb 2010
    Posts
    61
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    18

    Default Re: QListWidget refreshing issue

    Wow ! what a trick ! It works perfectly !

    Thank you so much for your help !

    And don't worry... I won't ask
    Best regards,

    ouekah

Similar Threads

  1. QListWidget issue
    By febil in forum Qt Programming
    Replies: 2
    Last Post: 18th February 2009, 12:54
  2. dropdown menu(popupmenu) refreshing issue
    By Ankit in forum Qt Programming
    Replies: 12
    Last Post: 24th August 2007, 05:57
  3. dropdown menu(popupmenu) refreshing issue
    By Ankit in forum Qt Tools
    Replies: 3
    Last Post: 17th August 2007, 14:09
  4. Refreshing issue
    By Ankit in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2007, 13:30
  5. QListWidget::currentItem() issue
    By high_flyer in forum Qt Programming
    Replies: 4
    Last Post: 16th April 2007, 12:04

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.