Additional QStatusbar



  • Hi

    I want to add an QStatusbar above a current QStatusbar in a QMainWindow. I am developing a hardware interface, which has a lot of status updates, but I don't want to clutter main window with bunch on updating labels.

    Using previous recommendations I added a layout (QVBoxLayout) named statusbar and added the additional QStatusbar to this.

    ui code snippet:

    <widget class="QWidget" name="verticalLayoutWidget">
        <property name="geometry">
         <rect>
          <x>-1</x>
          <y>251</y>
          <width>831</width>
          <height>21</height>
         </rect>
        </property>
        <layout class="QVBoxLayout" name="statusbar"/>
       </widget>
      </widget>
    

    cpp code snippet:

    //Add second statusbar
        statusCameraBar = new QStatusBar(this);
        ui_Spica->statusbar->addWidget(statusCameraBar); 
    

    I could then add updating labels using addPermanentWidget to it. It displays well.

    BUT: It is locked in place and does not resize with the MainWindow.

    How can I lock it to the current QStatusBar of the MainWindow so that it moves and resizes with it, or is there a way to add an additional Row of widgets to the current QStatusbar.

    I want to display 8 status labels in total spread over two levels.

    Please help
    Pat


  • Moderators

    @UFSBoyden Is ui_Spica->statusbar itself in a layout?



  • It is the layout. I is inside the MainWindow layout. See below the whole ui code...

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>MainWindow</class>
     <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>828</width>
        <height>337</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>MainWindow</string>
      </property>
      <property name="styleSheet">
       <string notr="true">background: url(:/stars.png);</string>
      </property>
      <widget class="QWidget" name="centralWidget">
       <property name="enabled">
        <bool>true</bool>
       </property>
       <property name="autoFillBackground">
        <bool>false</bool>
       </property>
       <widget class="QWidget" name="verticalLayoutWidget">
        <property name="geometry">
         <rect>
          <x>-1</x>
          <y>251</y>
          <width>831</width>
          <height>21</height>
         </rect>
        </property>
        <layout class="QVBoxLayout" name="statusbar"/>
       </widget>
      </widget>
      <widget class="QMenuBar" name="menuBar">
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
         <width>828</width>
         <height>26</height>
        </rect>
       </property>
      </widget>
      <widget class="QToolBar" name="mainToolBar">
       <property name="enabled">
        <bool>true</bool>
       </property>
       <attribute name="toolBarArea">
        <enum>TopToolBarArea</enum>
       </attribute>
       <attribute name="toolBarBreak">
        <bool>false</bool>
       </attribute>
      </widget>
      <widget class="QStatusBar" name="statusInfoBar">
       <property name="autoFillBackground">
        <bool>true</bool>
       </property>
      </widget>
     </widget>
     <layoutdefault spacing="6" margin="11"/>
     <resources/>
     <connections/>
    </ui>
    
    

    And in addition the constructor cpp code...

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui_Spica(new Ui::MainWindow)
    {
        ui_Spica->setupUi(this);
    
        //Set init variables to NULL
        winAbout = NULL;
        winInfo = NULL;
    
        //Set app environment and values, names, icons and etc.
        setWindowTitle("Spica");
        setWindowIcon(QIcon(":/resources/boyden.ico"));
    
        QPixmap bkgnd(":/resources/stars.xpm");
        QPalette palette;
        palette.setBrush(QPalette::Background, bkgnd);
        this->setPalette(palette);
    
        //Add second statusbar
        statusCameraBar = new QStatusBar(this);
        ui_Spica->statusbar->addWidget(statusCameraBar);
        statusCameraBar->setAutoFillBackground(true);
    
        //Add labels to camera status bar
        camconnect = new QLabel("Camera Offline", this);
        camconnect->setFrameStyle(QFrame::Panel | QFrame::Sunken);
        camstatus = new QLabel("Camera Status", this);
        camstatus->setFrameStyle(QFrame::Panel | QFrame::Sunken);
        camtemp = new QLabel("Camera Temp", this);
        camtemp->setFrameStyle(QFrame::Panel | QFrame::Sunken);
        camdrive = new QLabel("Camera Drive", this);
        camdrive->setFrameStyle(QFrame::Panel | QFrame::Sunken);
        statusCameraBar->addPermanentWidget(camconnect, 1);
        statusCameraBar->addPermanentWidget(camstatus, 1);
        statusCameraBar->addPermanentWidget(camtemp, 1);
        statusCameraBar->addPermanentWidget(camdrive, 1);
    
        //Add labels to info status bar
        telconnect = new QLabel("Telescope Offline", this);
        telconnect->setFrameStyle(QFrame::Panel | QFrame::Sunken);
        fwconnect = new QLabel("Filter Wheel Offline", this);
        fwconnect->setFrameStyle(QFrame::Panel | QFrame::Sunken);
        lst = new QLabel("LST", this);
        lst->setFrameStyle(QFrame::Panel | QFrame::Sunken);
        mjd = new QLabel("MJD", this);
        mjd->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    
        ui_Spica->statusInfoBar->addPermanentWidget(telconnect, 1);
        ui_Spica->statusInfoBar->addPermanentWidget(fwconnect, 1);
        ui_Spica->statusInfoBar->addPermanentWidget(lst, 1);
        ui_Spica->statusInfoBar->addPermanentWidget(mjd, 1);
    
    }
    

Log in to reply
 

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