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] How to embed icons into the status bar?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to embed icons into the status bar?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 8.4k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    roni
    wrote on last edited by
    #1

    Hello everybody,

    I would like to create status icons in the main window status bar. A good example is the network status icon with the tooltip in the Thunderbird window.

    !https://drive.google.com/file/d/0B3VIzaAFexv9T2ppMGhTWnZ2ZFU/view?usp=sharing()!

    In my case there should be multiple status icons, each representing an object in the list.

    Could you provide a simple code snippet or refer to an existing example online?

    Thank you in advance!

    Roni.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You can use QLabel where you set your various icons and then QStatusBar::addWidget to show them.

      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
      • R Offline
        R Offline
        roni
        wrote on last edited by
        #3

        Thank you for the reply, SGaist!

        Please clarify how to add QIcon to the QLablel. Does it have to be a QPicture?

        Below is a detailed description of what I am trying to acheive.

        The application is monitoring 3 local networks. The list of networks has 3 items:

        list = {net1, net2, net3}

        "net1" and "net2" are connected, "net3" is not. The status bar should have 3 icons: "connected", "connected", and "disconnected". The tooltip should show the network name.

        If a new network "net4" is discovered, the item is added to the list:

        list = {net1, net2, net3, net4}

        At this point the new icon should appear in the bar.

        If a connectivity status of a network changes, the corresponding icon should change accordingly.

        It seems like a very basic functionality. Yet I could not find related examples...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          No need for QIcon, just use the image you want on the QLabel. Since you will have several of those you can create a little class that will handle one network and change its icon accordingly.

          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
          • R Offline
            R Offline
            roni
            wrote on last edited by
            #5

            Thank you very much, SGaist! It worked:

            @QStatusBar * status_bar = statusBar();
            QLabel *label = new QLabel("", status_bar);
            QPixmap pixmap(QPixmap(":/images/network.png").scaledToHeight(status_bar->height()/2));

            label->setPixmap(pixmap);
            label->setToolTip(tr("net1"));

            status_bar->addWidget(label);@

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're welcome !

              If you are going to handle several interfaces, you should consider making that a little custom widget so you won't have to duplicate that much code.

              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
              • R Offline
                R Offline
                roni
                wrote on last edited by
                #7

                I already did :-)

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Perfect !

                  Then happy coding !

                  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

                  • Login

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