[SOLVED]add icon to a widget inside qmainwindow
-
wrote on 12 Apr 2014, 18:16 last edited by
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");
while(file2.read((char)&obj1,sizeof(obj1)))
{
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);
r=r+1;
}
table->resizeColumnsToContents();
QIcon icon(":/resources/release/icon.png");
setWindowIcon(icon);@plz help me its been bugging me a lot.
-
Hi,
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
-
wrote on 12 Apr 2014, 20:18 last edited by
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
-
Just realized something. You don't call setWindowIcon on your QTableWidget but on the containing widget
-
wrote on 12 Apr 2014, 23:45 last edited by
ill try that asap
-
wrote on 13 Apr 2014, 07:51 last edited by
It was a mistake on my part actually.
i changed
@setWindowIcon(icon);@
to
@table->setWindowIcon(icon);@and it worked;
thank you for your help
1/6