[SOLVED]add icon to a widget inside qmainwindow

  • i have a QTableWidget created if a particular action in activated in my qmainwindow. How to add icon to that widget??. This code is not working

    @QTableWidget table = new QTableWidget(num_obj,8);
    table->setHorizontalHeaderLabels(QStringList()<<"Diameter (in)"<<"Thickness (in)"<<"Nominal Weight (ppf)"<<"Threads & Couplings"<<"Grade"<<"Minimum Yield (psi)"<<"Maximum Yield (psi)"<<"Constant");
    QTableWidgetItem *item1 = new QTableWidgetItem(QString::number(obj1.diameter));
    table->setItem(r, 0, item1);
    QTableWidgetItem *item2 = new QTableWidgetItem(QString::number(obj1.thickness));
    table->setItem(r, 1, item2);
    QTableWidgetItem *item3 = new QTableWidgetItem(QString::number(obj1.nominal_wt));
    table->setItem(r, 2, item3);
    QTableWidgetItem *item4 = new QTableWidgetItem(QChar(obj1.threads_couplings));
    table->setItem(r, 3, item4);
    QTableWidgetItem *item5 = new QTableWidgetItem(QChar(obj1.grade));
    table->setItem(r, 4, item5);
    QTableWidgetItem *item6 = new QTableWidgetItem(QString::number(obj1.min_yield));
    table->setItem(r, 5, item6);
    QTableWidgetItem *item7 = new QTableWidgetItem(QString::number(obj1.avg_yield));
    table->setItem(r, 6, item7);
    QTableWidgetItem *item8 = new QTableWidgetItem(QString::number(obj1.constant));
    table->setItem(r, 7, item8);
    QIcon icon(":/resources/release/icon.png");

    plz help me its been bugging me a lot.

  • Lifetime Qt Champion


    Is your table widget standalone ? If so are you sure the path to the icon is correct ? You can check with isNull()

    Hope it helps

  • i have actions in my main window.
    one of the actions activates a function which creates this table widget.
    but only my mainwindow has icon and not this tablewidget that pops up.

    how to add icon to this widget

  • Lifetime Qt Champion

    Just realized something. You don't call setWindowIcon on your QTableWidget but on the containing widget

  • ill try that asap

  • It was a mistake on my part actually.
    i changed

    and it worked;

    thank you for your help

Log in to reply

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