Border of QToolBar not showing
-
I'm having trouble getting the border of my toolbar to show, which is located on a QWidget. Not sure if i have to set parents or something similar.
My code: ( I'm only setting up p1 for now to save code. )
@MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
QWidget *p1 = new QWidget;
QWidget *p2 = new QWidget;
QWidget *p3 = new QWidget;
QWidget *p4 = new QWidget;QWidget *view = new QTextEdit; QVBoxLayout *vbox = new QVBoxLayout; QToolBar *toolBar = new QToolBar; toolBar->addAction("file"); vbox->addWidget(toolBar); vbox->addWidget(view); vbox->setContentsMargins(0,0,0,0); vbox->setSpacing(0); p1->setLayout(vbox); QWidget *wnd = new QWidget; QWidget *container_1 = new QWidget; QWidget *container_2 = new QWidget; QHBoxLayout *h_layout1 = new QHBoxLayout; QHBoxLayout *h_layout2 = new QHBoxLayout; QVBoxLayout *v_layout3 = new QVBoxLayout; QSplitter *split1 = new QSplitter; QSplitter *split2 = new QSplitter; QSplitter *split3 = new QSplitter; split1->addWidget(p1); split1->addWidget(p2); split2->addWidget(p3); split2->addWidget(p4); h_layout1->addWidget(split1); h_layout2->addWidget(split2); container_1->setLayout(h_layout1); container_2->setLayout(h_layout2); split3->setOrientation(Qt::Vertical); split3->addWidget(container_1); split3->addWidget(container_2); v_layout3->addWidget(split3); wnd->setLayout(v_layout3); setCentralWidget(wnd);
}@
-
since QToolBar derives from QWidget and not from QFrame you won't be able to add a (drawn) border to it.
-
imho QToolBar,QWidget can have border ... :)
I tested your code and it's working:
@...
QToolBar *toolBar = new QToolBar;
toolBar->setStyleSheet("QToolBar{border:1px solid rgb(255,0,0);}");
...@ -
right ... i checked the style painting code.
My fault ... sorry for that! -
Thanks for the help! But I thought that QToolBar had a default border.
I'm looking for something like this:
!http://img69.imageshack.us/img69/1155/cyfi.png!But getting this:
!http://img15.imageshack.us/img15/3606/7onj.png! -
you could place the tool bar inside a QFrame though and set the frame style on it. This should give you something like in the first screenshot.
-
The picture I referenced is using the same code as me, but I'm getting a different result. I think it has to do with setting up the parents, but not sure. Here is the "link":http://qt-project.org/forums/viewthread/3647to his code.