Skip to content

Instantly share code, notes, and snippets.

@manashmandal
Created April 13, 2016 05:49
Show Gist options
  • Save manashmandal/4c16fce3c1c5dde07cfabac7f718181a to your computer and use it in GitHub Desktop.
Save manashmandal/4c16fce3c1c5dde07cfabac7f718181a to your computer and use it in GitHub Desktop.
#include "qmainwidget.h"
#include "ui_qmainwidget.h"
QMainWidget::QMainWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::QMainWidget)
{
ui->setupUi(this);
}
QMainWidget::~QMainWidget()
{
delete ui;
}
void QMainWidget::on_addBtn_clicked()
{
//Creating a new list widget item whose parent is the listwidget itself
QListWidgetItem *listWidgetItem = new QListWidgetItem(ui->listWidget);
//Adding the item to the listwidget
ui->listWidget->addItem (listWidgetItem);
//Creating an object of the designed widget which is to be added to the listwidget
TheWidgetItem *theWidgetItem = new TheWidgetItem;
//Making sure that the listWidgetItem has the same size as the TheWidgetItem
listWidgetItem->setSizeHint (theWidgetItem->sizeHint ());
//Finally adding the itemWidget to the list
ui->listWidget->setItemWidget (listWidgetItem, theWidgetItem);
}
void QMainWidget::on_delBtn_clicked()
{
//Delete selected item from the listWidget
delete ui->listWidget->currentItem ();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment