Search code examples
c++qtuser-interfacestatusbar

Qt QStatusBar wider separator


I am using qt to develop an embedded gui application. I am using 2 QStatusBars to make a menu-like buttons one can see on an osciloscope for example:

enter image description here

My problem is I dont know a proper way of separating the buttons from eachother with a certain width. In the picture you can see I have added couple separators to achieve that, but it doesnt look that way when run on the target.

Is there a better way to separate buttons on QStatusBar with certain width?


Solution

  • I'd prefer you use a blank widget to do the seperation as suggested by Martin, like so;

    //the 2 widgets in the status bar
    button1 = new QPushButton("Button1");
    button2 = new QPushButton("Button2");
    
    //the blank widget. You can set your width with 'setFixedWidth(int)'
    widget = new QWidget;
    widget->setFixedWidth(50);
    widget->setHidden(1);
    widget->setVisible(1);
    
    //placing them in the status bar
    statusBar = new QStatusBar;
    statusBar->addWidget(button1);
    statusBar->addWidget(widget);
    statusBar->addWidget(button2);