Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Custom Widget in QListWidget doesn't show correct in list

  1. #1
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Custom Widget in QListWidget doesn't show correct in list

    I created a custom widget in Qt designer, (with source for changing properties) consisting of a label, progress bar and a checkbox. I have that as an object in a mainwindow to display in a list when triggered. The first trigger displays the widget. Each successive trigger displays the widget in a subsequent row down the list but there only exists one widget with empty rows above.

    Widget Code:
    Controls.h
    Qt Code:
    1. #ifndef CONTROLS_H
    2. #define CONTROLS_H
    3.  
    4. #include <QWidget>
    5.  
    6. namespace Ui {
    7. class Controls;
    8. }
    9.  
    10. class Controls : public QWidget
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit Controls(QWidget *parent = 0);
    16. ~Controls();
    17.  
    18. public:
    19. Ui::Controls* ui;
    20.  
    21. public slots:
    22. void WriteInfoNumber(int);
    23.  
    24. private:
    25. // Ui::Controls *ui;
    26. };
    27.  
    28. #endif // CONTROLS_H
    To copy to clipboard, switch view to plain text mode 

    Controls.cpp
    Qt Code:
    1. #include "controls.h"
    2. #include "ui_controls.h"
    3.  
    4. #include <QDebug>
    5.  
    6. Controls::Controls(QWidget *parent) : QWidget(parent), ui(new Ui::Controls)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. Controls::~Controls()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void Controls::WriteInfoNumber(int value)
    17. {
    18. qDebug() << "ID Value = " << value;
    19. ui->label->setText(QString::number(value));
    20. }
    To copy to clipboard, switch view to plain text mode 

    MainWindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "controls.h"
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. signals:
    20. void UpdateInfo(int);
    21.  
    22. private slots:
    23. void on_actionFile_triggered();
    24.  
    25. void on_actionE_xit_triggered();
    26.  
    27. private:
    28. Ui::MainWindow* ui;
    29. Controls* ctls;
    30. };
    31.  
    32. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "ui_Controls.h"
    4. #include <QTime>
    5.  
    6. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. ctls = new Controls();
    10. connect(this, SIGNAL(UpdateInfo(int)), ctls, SLOT(WriteInfoNumber(int)));
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    17.  
    18. void MainWindow::on_actionE_xit_triggered()
    19. {
    20. QApplication::quit();
    21. }
    22.  
    23. void MainWindow::on_actionFile_triggered()
    24. {
    25. QTime t = QTime::currentTime();
    26. QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
    27. item->setSizeHint(QSize(300, 35));
    28. ui->listWidget->insertItem(ui->listWidget->size().height(),item);
    29. ui->listWidget->setItemWidget(item, ctls);
    30. emit UpdateInfo(t.msec());
    31. }
    To copy to clipboard, switch view to plain text mode 

    It seems so straightforward. Don't know what I'm missing.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    You only have one object of type Controls, obviously it can only be displayed in one place.

    Cheers,
    _

    P.S.:you don't need to insert the QListWidgetItem, passing the list widget to the constructor takes care of that already.

  3. #3
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by anda_skoa View Post
    You only have one object of type Controls, obviously it can only be displayed in one place.

    Cheers,
    _

    P.S.:you don't need to insert the QListWidgetItem, passing the list widget to the constructor takes care of that already.
    Yes that's correct. I only want one type of object displayed in the list. I want to add it to the list for every trigger so as to get a list of rows of the object displayed.

    Hope that's clearer than what I originally wrote.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    What anda_skoa said was, "You only have one object of type Controls", not "You only have one type of object." It stands to reason that a single Controls widget can be displayed in only the one place. If you want to simultaneously display multiple widgets of type Controls then you need to create multiple objects of that type.

  5. #5
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by ChrisW67 View Post
    What anda_skoa said was, "You only have one object of type Controls", not "You only have one type of object." It stands to reason that a single Controls widget can be displayed in only the one place. If you want to simultaneously display multiple widgets of type Controls then you need to create multiple objects of that type.
    .

    Right!

    So call new Controls() in line 29 rather than ctls does the trick for handling multiple entries but breaks the emitted signal for updating the label part of the custom widget. What broke? Perhaps I need a different sender in the signal/slot line in the ctor?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by astodolski View Post
    .
    So call new Controls() in line 29 rather than ctls does the trick for handling multiple entries but breaks the emitted signal for updating the label part of the custom widget. What broke? Perhaps I need a different sender in the signal/slot line in the ctor?
    How do you connect now?

    Cheers,
    _

  7. #7
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by anda_skoa View Post
    How do you connect now?

    Cheers,
    _
    Line 10 MainWindow.cpp. I connect the emitted signal to the method WriteInfoNumber in Control.cpp

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    That was from before, when you had only one instance.

    If you want all instances of your widget to receive the signal, you need to connect to each one after its respective creation.

    Cheers,
    _

  9. #9
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by anda_skoa View Post
    That was from before, when you had only one instance.

    If you want all instances of your widget to receive the signal, you need to connect to each one after its respective creation.

    Cheers,
    _
    So my trigger method is now as follows:

    Qt Code:
    1. void MainWindow::on_actionFile_triggered()
    2. {
    3. QTime t = QTime::currentTime();
    4. QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
    5. item->setSizeHint(QSize(300, 35));
    6. ui->listWidget->insertItem(ui->listWidget->size().height(),item);
    7. ui->listWidget->setItemWidget(item, new Controls);
    8. emit UpdateInfo(t.msec());
    9. }
    To copy to clipboard, switch view to plain text mode 

    The slot connected to UpdateInfo does not change the label. If as you suggest, I connect to each successive instance, I still don't get a change in the label from the slot associated. What I do see however is a call to the slot for each entry in the list: i.e 1 call for the first, 2 calls for the second entry, 3 calls for the third in the list etc.

    Should there be a different connect?

    What I was able to do as perhaps an interitm step is to call the following which fortunately sets the text for the label:
    Qt Code:
    1. item->setText(QString::number(t.msec()));
    To copy to clipboard, switch view to plain text mode 

    Since I have two other controls, that being a progress bar and the other a checkbox, I still am not sure how to set those other items in the custom widget
    Last edited by astodolski; 19th February 2014 at 14:50.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by astodolski View Post
    So my trigger method is now as follows:

    Qt Code:
    1. void MainWindow::on_actionFile_triggered()
    2. {
    3. QTime t = QTime::currentTime();
    4. QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
    5. item->setSizeHint(QSize(300, 35));
    6. ui->listWidget->insertItem(ui->listWidget->size().height(),item);
    7. ui->listWidget->setItemWidget(item, new Controls);
    8. emit UpdateInfo(t.msec());
    9. }
    To copy to clipboard, switch view to plain text mode 
    That is still missing the connect

    Qt Code:
    1. void MainWindow::on_actionFile_triggered()
    2. {
    3. QTime t = QTime::currentTime();
    4. QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
    5. item->setSizeHint(QSize(300, 35));
    6.  
    7. // create instance of Controls
    8. Controls *ctls = new Controls;
    9.  
    10. // connect signal to Controls instance
    11. connect(this, SIGNAL(UpdateInfo(int)), ctls, SLOT(WriteInfoNumber(int)));
    12.  
    13. ui->listWidget->setItemWidget(item, ctls);
    14. emit UpdateInfo(t.msec());
    15. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  11. #11
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by anda_skoa View Post
    That is still missing the connect

    Qt Code:
    1. void MainWindow::on_actionFile_triggered()
    2. {
    3. QTime t = QTime::currentTime();
    4. QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
    5. item->setSizeHint(QSize(300, 35));
    6.  
    7. // create instance of Controls
    8. Controls *ctls = new Controls;
    9.  
    10. // connect signal to Controls instance
    11. connect(this, SIGNAL(UpdateInfo(int)), ctls, SLOT(WriteInfoNumber(int)));
    12.  
    13. ui->listWidget->setItemWidget(item, ctls);
    14. emit UpdateInfo(t.msec());
    15. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _
    I may be misunderstanding. The Controls instance is the object named ctls. The signal UpdateInfo is connected to the WriteInfoNumber slot belonging to the Controls class.

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by astodolski View Post
    The Controls instance is the object named ctls.
    Yes.

    Quote Originally Posted by astodolski View Post
    The signal UpdateInfo is connected to the WriteInfoNumber slot belonging to the Controls class.
    Yes. The connect() call's arguments are:

    1) sender object
    2) signal
    3) receiver object
    4) slot

    Your original code was creating a Controls instance in the constructor and connected to it.
    Your new code creates new Controls instances on every actionFile triggered(). If you want those instances to receive the signal as well, you connect to them as well.

    Cheers,
    _

  13. #13
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by anda_skoa View Post
    Yes.


    Yes. The connect() call's arguments are:

    1) sender object
    2) signal
    3) receiver object
    4) slot

    Your original code was creating a Controls instance in the constructor and connected to it.
    Your new code creates new Controls instances on every actionFile triggered(). If you want those instances to receive the signal as well, you connect to them as well.

    Cheers,
    _
    If I copy the connect call from the ctor to the actionFile_triggered() method, the SLOT gets called for every entry that's in the list. That is for the initial entry, one call. The next instance doesn't signal the slot once, it get's called twice and so on. How do I fix that?

  14. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    I am not sure I understand, the slot should only get called once per receiver object.

    Do something like this in the slot

    Qt Code:
    1. qDebug() << Q_FUNC_INFO << "this=" << this;
    To copy to clipboard, switch view to plain text mode 
    and check if "this" is the same twice per emit.

    Cheers,
    _

  15. #15
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by anda_skoa View Post
    I am not sure I understand, the slot should only get called once per receiver object.

    Do something like this in the slot

    Qt Code:
    1. qDebug() << Q_FUNC_INFO << "this=" << this;
    To copy to clipboard, switch view to plain text mode 
    and check if "this" is the same twice per emit.

    Cheers,
    _
    I will try this but in the meantime look at the slot in Controls.cpp It contains a debug statement:
    Qt Code:
    1. qDebug() << "ID Value = " << value;
    To copy to clipboard, switch view to plain text mode 

    For every instance the slot gets called the number of entries in the list. All the code for this small sample is posted. Maybe you can load it and run it to see what I mean. A UI which isn't posted will have to be created to have the three controls that is supposed to be in the custom widget.

    Update:

    The results of your suggestion is as follows:

    Qt Code:
    1. ID Value = 268
    2. void __thiscall Controls::WriteInfoNumber(int) this= Controls(0x389ef0, name = "Controls")
    3. ID Value = 147
    4. void __thiscall Controls::WriteInfoNumber(int) this= Controls(0x389ef0, name = "Controls")
    5. ID Value = 147
    6. void __thiscall Controls::WriteInfoNumber(int) this= Controls(0x389ef0, name = "Controls")
    7. ID Value = 627
    8. void __thiscall Controls::WriteInfoNumber(int) this= Controls(0x389ef0, name = "Controls")
    9. ID Value = 627
    10. void __thiscall Controls::WriteInfoNumber(int) this= Controls(0x389ef0, name = "Controls")
    11. ID Value = 627
    12. void __thiscall Controls::WriteInfoNumber(int) this= Controls(0x389ef0, name = "Controls")
    To copy to clipboard, switch view to plain text mode 

    That's when calling on_actionFile_triggered() 3 times!
    Last edited by astodolski; 20th February 2014 at 17:56.

  16. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    I pieced together the bits and created dummy .ui files and I get this

    Qt Code:
    1. created new control Controls(0x20c5340, name = "Controls")
    2. this= Controls(0x20c5340, name = "Controls") ID Value = 503
    3. created new control Controls(0x20757d0, name = "Controls")
    4. this= Controls(0x20c5340, name = "Controls") ID Value = 511
    5. this= Controls(0x20757d0, name = "Controls") ID Value = 511
    6. created new control Controls(0x20f4d40, name = "Controls")
    7. this= Controls(0x20c5340, name = "Controls") ID Value = 26
    8. this= Controls(0x20757d0, name = "Controls") ID Value = 26
    9. this= Controls(0x20f4d40, name = "Controls") ID Value = 26
    To copy to clipboard, switch view to plain text mode 

    The "created new control" comes right from after creating the control inside the slot
    Qt Code:
    1. void MainWindow::on_actionFile_triggered()
    2. {
    3. QTime t = QTime::currentTime();
    4. QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
    5. item->setSizeHint(QSize(300, 35));
    6. ctls = new Controls();
    7. qDebug() << "created new control" << ctls;
    8. connect(this, SIGNAL(UpdateInfo(int)), ctls, SLOT(WriteInfoNumber(int)));
    9. ui->listWidget->setItemWidget(item, ctls);
    10. emit UpdateInfo(t.msec());
    11. }
    To copy to clipboard, switch view to plain text mode 
    The other one obviously from the slot in Controls.

    As we can see, the first control is created, it receives the signal. Then he second control is created and both instances get the signals, as expected
    Then a third control is created and, again as expected, all three get the signal.

    Now, I have no idea why you want all of them to show the same value, but the do. No receiver's slot is called twice per emit.

    Cheers,
    _

  17. #17
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by anda_skoa View Post
    I pieced together the bits and created dummy .ui files and I get this

    Qt Code:
    1. created new control Controls(0x20c5340, name = "Controls")
    2. this= Controls(0x20c5340, name = "Controls") ID Value = 503
    3. created new control Controls(0x20757d0, name = "Controls")
    4. this= Controls(0x20c5340, name = "Controls") ID Value = 511
    5. this= Controls(0x20757d0, name = "Controls") ID Value = 511
    6. created new control Controls(0x20f4d40, name = "Controls")
    7. this= Controls(0x20c5340, name = "Controls") ID Value = 26
    8. this= Controls(0x20757d0, name = "Controls") ID Value = 26
    9. this= Controls(0x20f4d40, name = "Controls") ID Value = 26
    To copy to clipboard, switch view to plain text mode 

    The "created new control" comes right from after creating the control inside the slot
    Qt Code:
    1. void MainWindow::on_actionFile_triggered()
    2. {
    3. QTime t = QTime::currentTime();
    4. QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
    5. item->setSizeHint(QSize(300, 35));
    6. ctls = new Controls();
    7. qDebug() << "created new control" << ctls;
    8. connect(this, SIGNAL(UpdateInfo(int)), ctls, SLOT(WriteInfoNumber(int)));
    9. ui->listWidget->setItemWidget(item, ctls);
    10. emit UpdateInfo(t.msec());
    11. }
    To copy to clipboard, switch view to plain text mode 
    The other one obviously from the slot in Controls.

    As we can see, the first control is created, it receives the signal. Then he second control is created and both instances get the signals, as expected
    Then a third control is created and, again as expected, all three get the signal.

    Now, I have no idea why you want all of them to show the same value, but the do. No receiver's slot is called twice per emit.

    Cheers,
    _
    I appreciate you staying with me on this problem. However your observation is incorrect. The "ID Value = " does in fact get displayed more times than it is supposed to. There should ONLY be one ID value for each instance - at least that's what the goal is:

    MainWindowImage.jpg

    Qt Code:
    1. created new control Controls(0x5b16b8, name = "Controls")
    2. ID Value = 309
    3. void __thiscall Controls::WriteInfoNumber(int) this = Controls(0x5b16b8, name = "Controls")
    4. created new control Controls(0x5df218, name = "Controls")
    5. ID Value = 802
    6. void __thiscall Controls::WriteInfoNumber(int) this = Controls(0x5b16b8, name = "Controls")
    7. ID Value = 802
    8. void __thiscall Controls::WriteInfoNumber(int) this = Controls(0x5df218, name = "Controls")
    9. created new control Controls(0x5dfda8, name = "Controls")
    10. ID Value = 896
    11. void __thiscall Controls::WriteInfoNumber(int) this = Controls(0x5b16b8, name = "Controls")
    12. ID Value = 896
    13. void __thiscall Controls::WriteInfoNumber(int) this = Controls(0x5df218, name = "Controls")
    14. ID Value = 896
    15. void __thiscall Controls::WriteInfoNumber(int) this = Controls(0x5dfda8, name = "Controls")
    To copy to clipboard, switch view to plain text mode 

    If I debug into the slot for Controls, it does get hit as many times as the debug statements show.
    Last edited by astodolski; 20th February 2014 at 20:56.

  18. #18
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    That shows the same output as for me, i.e. each Controls's slot is called once per signal emit.

    Every time the signal gets emitted, the main window sends a single value to all objects that are connected to that signal.
    At first there is only one object, so only one debug output it shown.
    Then there are two receiver objects, so two debug outputs are shown, and so on.

    A signal "broadcasts" information, anyone interested in that information can connect to the signal and get notified about these broadcasts. Each receiver is independent of any other, all receive the information equally, just like if they were the only receiver.

    The current code is doing what your initial code attempted to do: having "one" object in every row, the value updating simultaniously in all rows.

    Is this is not what you were aiming at then this is the wrong approach

    Cheers,
    _

  19. #19
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by anda_skoa View Post
    That shows the same output as for me, i.e. each Controls's slot is called once per signal emit.
    For each emit of the signal UpdateInfo, a breakpoint on the slot it is connected to gets a hit more than once after the initial instance. I illustrated that with the debug output as well as the screen shot.

    The current code is doing what your initial code attempted to do: having "one" object in every row, the value updating simultaniously in all rows.
    Well, not exactly. One object per row, sure. The ID which I represented by a time interval is expected to be a unique number for each instance. The same value in all rows is definitely not what is intended.

    Is this is not what you were aiming at then this is the wrong approach
    Cheers,
    _
    I hope I at least conveyed the right approach

  20. #20
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Widget in QListWidget doesn't show correct in list

    Quote Originally Posted by astodolski View Post
    For each emit of the signal UpdateInfo, a breakpoint on the slot it is connected to gets a hit more than once after the initial instance.
    A breakpoint on a method is hit every time the method is invoked. Since you have multiple objects of that class, and all their slots are connected, your breakpoint is hit once per instance.

    Quote Originally Posted by astodolski View Post
    Well, not exactly. One object per row, sure. The ID which I represented by a time interval is expected to be a unique number for each instance. The same value in all rows is definitely not what is intended.
    So does this value change over time?
    If not, why use a signal and not just imply pass the value via a setter or constructor argument?

    Cheers,
    _

Similar Threads

  1. Replies: 4
    Last Post: 18th October 2013, 17:15
  2. Replies: 8
    Last Post: 21st May 2010, 11:26
  3. QListWidget doesn't show icons
    By franco.amato in forum Qt Programming
    Replies: 8
    Last Post: 16th March 2010, 14:15
  4. Custom Widget doesn t show.
    By Frej in forum Qt Tools
    Replies: 12
    Last Post: 11th March 2010, 10:48
  5. QMainWindow and custom widget doesn't show
    By Peppy in forum Qt Programming
    Replies: 9
    Last Post: 26th December 2009, 15:09

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.