Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    [SOLVED]add icon to a widget inside qmainwindow

    General and Desktop
    2
    6
    1581
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      poketmonister 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.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • P
          poketmonister 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

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • P
              poketmonister last edited by

              ill try that asap

              1 Reply Last reply Reply Quote 0
              • P
                poketmonister 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 Reply Last reply Reply Quote 0
                • First post
                  Last post