Results 1 to 4 of 4

Thread: setItemWidget in QWidgetList does not work

  1. #1
    Join Date
    Mar 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11
    Thanks
    1

    Default setItemWidget in QWidgetList does not work

    Hey

    i want to create a list of widges. each item should have a label and three buttons (like my SSH_list_item). i tried it like this:


    Qt Code:
    1. void sshfsGUI::create_new_entry(QString name, QString mountpoint, QString address){
    2. SSH_list_item* list_item = new SSH_list_item(name, mountpoint, address, this);
    3. QListWidgetItem* item = new QListWidgetItem(name);
    4. ui->SSH_List->addItem(name);
    5. ui->SSH_List->setItemWidget(item, list_item);
    6. list_item->show();
    7. }
    To copy to clipboard, switch view to plain text mode 

    the class looks like this:

    Qt Code:
    1. class SSH_list_item : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit SSH_list_item(QWidget *parent = 0);
    7. SSH_list_item(QString _name, QString _mountpoint, QString _address, QWidget *parent=0);
    8. ~SSH_list_item();
    9.  
    10. private:
    11. Ui::SSH_list_item *ui;
    12. QString name, mountpoint, address;
    13. };
    To copy to clipboard, switch view to plain text mode 

    but what i get is a list of strings and the widget as a separate window. when i leave out " list_item->show();" there is only the list of strings.
    here is a screenshot: http://imageshack.us/photo/my-images...eenshotro.png/
    what am i doing wrong?

  2. #2
    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: setItemWidget in QWidgetList does not work

    Your "item" has no relation to the list widget. You are adding a string to the list which effectively creates a new item independent of your "item" object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Quabla (14th March 2013)

  4. #3
    Join Date
    Mar 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: setItemWidget in QWidgetList does not work

    thank you i changed it to

    Qt Code:
    1. void sshfsGUI::create_new_entry(QString name,QString mountpoint ,QString address){
    2. SSH_list_item* list_item = new SSH_list_item(name, mountpoint, address, this);
    3. QListWidgetItem* item = new QListWidgetItem(name);
    4. ui->SSH_List->addItem(item);
    5. ui->SSH_List->setItemWidget(item, list_item);
    6. list_item->show();
    7. }
    To copy to clipboard, switch view to plain text mode 

    now there is only the string list. the seperate windows do not appear anymore

    edit: ok the mistake is in the order. i have to show the widget before adding it, like this:
    Qt Code:
    1. void sshfsGUI::create_new_entry(QString name,QString mountpoint ,QString address){
    2. SSH_list_item* list_item = new SSH_list_item(name, mountpoint, address, this);
    3. QListWidgetItem* item = new QListWidgetItem(name);
    4. list_item->show();
    5. ui->SSH_List->addItem(item);
    6. ui->SSH_List->setItemWidget(item, list_item);
    7. }
    To copy to clipboard, switch view to plain text mode 

    but there are new issues: only the widget of the last SSH_list_item added is visible and the name of it appears to times. and when i change the size og the main widget, the SSH_list_item widget disappears and again all i see is the string list.
    sycreenshot: http://imageshack.us/photo/my-images...enshotpso.png/
    Last edited by Quabla; 15th March 2013 at 00:16.

  5. #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: setItemWidget in QWidgetList does not work

    Your problem has to be elsewhere. The code you posted looks fine.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Do I need to destroy the widget of setItemWidget?
    By qlands in forum Qt Programming
    Replies: 2
    Last Post: 30th May 2011, 15:24
  2. Replies: 5
    Last Post: 19th April 2011, 13:57
  3. Replies: 0
    Last Post: 29th November 2010, 06:34
  4. extern QWidgetList *qt_modal_stack
    By Alex_123 in forum Qt Programming
    Replies: 5
    Last Post: 20th December 2008, 13:24
  5. QWidgetList
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2007, 08:53

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.