Qt QHBoxLayout issue?

I use an extended QGroupBox as the widget for QDockWidget in my QMainWindow. Here is the code snippet:

RzPlaneViewerControlPanelWidget::RzPlaneViewerControlPanelWidget(QWidget *parent) : QGroupBox(parent) {
        // TODO Auto-generated constructor stub
        init();

    }

void RzPlaneViewerControlPanelWidget::init()
    {

            QHBoxLayout *hbox=new QHBoxLayout;
            hbox->setSizeConstraint(hbox->SetMinimumSize);
            hbox->setSpacing(0);
            hbox->setStretch(1,0);

            setMaximumHeight(50);

            QScrollBar *scrollbar=new QScrollBar;
            scrollbar->setOrientation(Qt::Horizontal);
            scrollbar->setMouseTracking(true);
            scrollbar->setFocusPolicy(Qt::StrongFocus);
            scrollbar->setMinimum(0);
            scrollbar->setSingleStep(1);



            QLineEdit *qlineedit = new QLineEdit;
            qlineedit->setMaximumWidth(60);
            qlineedit->setReadOnly(true);

            hbox->addWidget(scrollbar);
            hbox->addWidget(qlineedit);

            //hbox->addWidget(new )
            setLayout(hbox);

}

Here is how I add this widget to QDockWidget :

RzPlaneViewerControlPanelWidget *controlPanel=new RzPlaneViewerControlPanelWidget ;
controlPanel->init();

QDockWidget controlPanelDockWidet=new QDockWidget;
controlPanelDockWidet->setAllowedAreas(Qt::BottomDockWidgetArea);
controlPanelDockWidet->setFeatures(QDockWidget::DockWidgetVerticalTitleBar);
controlPanelDockWidet->setWidget(controlPanel);

But the ScrollBar is not stretched as I expected - Here's how it looks like -

This is what I want -

Answers


From a quick read, I'd try doing:

hbox->addWidget(scrollbar, 1);

The second (optional) argument to addWidget is the stretch factor. From the Qt docs:

If the stretch factor is 0 and nothing else in the QBoxLayout has a stretch factor greater than zero, the space is distributed according to the QWidget:sizePolicy() of each widget that's involved.

Also, note that your:

hbox->setStretch(1,0);

call does not have any effect, as it is setting the qlineedit's stretch factor to 0, but that's already the default.


Need Your Help

Simple: NSArray object to Double?

iphone objective-c casting

I have a NSArray with numbers and I want to get the value of an item of the array and assign it to a double. In my attempt of simple casting:

jQuery Autocomplete - When an item is selected from the list store it in a php variable

php jquery autocomplete

Once someone selects an item from the list of autocomplete options, how can I store the id of that item as a variable to be used in other php scripts?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.