Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]add icon to a widget inside qmainwindow

[SOLVED]add icon to a widget inside qmainwindow

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.9k Views
  • 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 Offline
    P Offline
    poketmonister
    wrote on 12 Apr 2014, 18:16 last edited by
    #1

    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
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Apr 2014, 19:39 last edited by
      #2

      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
      0
      • P Offline
        P Offline
        poketmonister
        wrote on 12 Apr 2014, 20:18 last edited by
        #3

        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
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Apr 2014, 22:04 last edited by
          #4

          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
          0
          • P Offline
            P Offline
            poketmonister
            wrote on 12 Apr 2014, 23:45 last edited by
            #5

            ill try that asap

            1 Reply Last reply
            0
            • P Offline
              P Offline
              poketmonister
              wrote on 13 Apr 2014, 07:51 last edited by
              #6

              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
              0

              1/6

              12 Apr 2014, 18:16

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved