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



  • 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.


  • Lifetime Qt Champion

    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



  • 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...


  • Lifetime Qt Champion

    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.



  • 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);@


  • Lifetime Qt Champion

    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.



  • I already did :-)


  • Lifetime Qt Champion

    Perfect !

    Then happy coding !


Log in to reply
 

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