error: 'QWidget::QWidget(const QWidget&)' is private Q_DISABLE_COPY(QWidget)

  • Hey,
    Two errors here:

    1: ...\qwidget.h: error: 'QWidget::QWidget(const QWidget&)' is private
         Q_DISABLE_COPY(QWidget) // I guess this is probably the main problem
    2: ...\qlist.h: error: use of deleted function 'QWidget::QWidget(const QWidget&)'

    These I get multiple times at different locations in the two files.
    I am trying to set up a easy QAbstractListModel with widgets (just QWidgets with different background color).
    This is where I try to add widgets to the model in mainwindow.cpp :

        QList<QWidget> widgets;
        QWidget w1;
        w1.setStyleSheet("background-color: black");
        QWidget w2;
        w1.setStyleSheet("background-color: blue");
        QWidget w3;
        w1.setStyleSheet("background-color: green");
        widgets << w1 << w2 << w3;
        model->addPieces(widgets); // model is a object of a custom QAbstractListModel derived class

    addPieces in the model class:

    void MyListModel::addPieces(const QList<QWidget> &widgts)

    I am guided by the puzzle-example.
    Can you tell me, why I get these errors? What am I missing?
    Thanks for answers!

  • Qt Champions 2018

    QObjects can't be copied. you can have a QList<QWidget*> but not a QList<QWidget>.

    Having said that. Stop immediately whatever you are doing.
    The model should not take care of rendering.
    If you want to color a cell just use QStandardItemModel and call model->setData(model->index(row,column),QBrush(Qt::black),Qt::BackgroundRole );
    See for more details on model/view/delegate

  • @VRonin
    Ok, thanks.
    Just thought, this would be a legitim way, because I just looked to the puzzle-example and there it is also made this way (but with Pixmaps) and this example shows what I want to have in the end.

  • Lifetime Qt Champion


    QPixmap is not a QObject that's why it works in that case. Not all Qt classes derive from QObjects.

  • @SGaist
    Ohhh, that makes sense.
    Now I use a delegate class and I want to display a custom widget by me to get what I tried to do above. The model holds only the title (and some more icons later) and the view just should display these custom widgets as items (and in the custom widgets, the corresponding title will be shown). How can I make my delegate class creating and displaying these widgets (I already have the widget class) and using them as items in the ListView?

  • Qt Champions 2018

    • Do you really need to display widgets?
    • could you handle the paint efficiently yourself?

    If you really answered yes and no then you can use: but be mindful performance will be impacted

  • @VRonin
    Ok... I just don't get the problem here...
    Everywhere in every program we use, we have lists of widgets (or a treeView), that are draggabe into another area/over another widget, that then reacts to it. Why is this such a problem?
    I don't know exactely what you mean with handeling the paint event myself. Why can't I just change the displaying part. Anywhere, there must be a function, that draws the items of the list. Why can't I just redict the painting signal to the correseponding widget?

  • Lifetime Qt Champion

    Having a list of real widgets is heavy to draw.
    if you plan on run on smaller boards ,it will not
    scroll nicely if u have many items.
    The solution to this - is a delegate the at draw the look of the widget,
    but it IS not a full widget unless you click on it.
    When clicked Then delegate via Editor, use a the real widget and user can interact with it on the
    current select row/col. As soon as its not the active one, its only drawn by
    manual painter operations.
    That is how a delegate help performance.
    By NOt being a big is list of real widgets but only the current one is real and rest
    is not.

    Try the code VRonin links to. its his creation and very useful!

  • @mrjj
    Ok, makes sense.
    Is it possible to anyway seperate the delegate from the actual widget painting in code? So that I can do something like

    void MyItemDelegate::paint(QPainter *painter, /* and all other stuff */) const{
        widgetItems.value(index.row())->myCustomPaintFunction(painter); // widgetItems = QList<WidgetItem*> widgetItems;
                                        //WidgetItem = just a standalone C++ class
    WidgetItem::myCustomPaintFunction(QPainter *painter){
        // draw the shape

    It would be a bit clearer to seperate it this way

  • Qt Champions 2018

    In general yes, what you wrote, however is conceptually wrong. widgetItems.value(index.row()) implies the delegate owns/is the model which is unusual at least

  • @VRonin
    Well yes, I should store the actual data in a model, that is able to return this data correctly.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.