PDA

View Full Version : drawing an unfixed line?



tommy
23rd January 2008, 20:38
I think QLine is used to draw fixed lines on the main window. But I'd like to be able to draw vertical and horizontal lines on the main layout in order to use them as separators. I don't want them to be fixed to any position but I'd like them to change their position as the main layout is shrinked and expanded by the user - kind of like the addStretch() works.
More specifiacally: I have two widgets on the screen and I'd like to have a vertical line between then to act as a separator. When user expands the window, I'd like the line to stay between the two widgets and also equal distance from each. I need this to create some order and make my layout look less busy.

jpn
23rd January 2008, 21:10
http://www.qtcentre.org/forum/f-qt-programming-2/t-best-way-to-draw-a-line-11371.html

tommy
23rd January 2008, 22:43
I leaned to use HBox and I was able to draw the lines I wanted.
I'd like to know how to draw a box around a widget on the screen. The below code draws a box but I can't make it to include anything.



QLabel *hDivider1 = new QLabel;
hDivider1->setFrameStyle(QFrame::Box | QFrame::Sunken);
hDivider1->setLineWidth(2);

clusterLayout->addWidget(hDivider1);

jpn
24th January 2008, 06:01
Install a layout on the frame and add widgets to it.

tommy
25th January 2008, 13:56
This is a good idea. However, I could really use a bit of help here. I don't know how to install a layout on the frame. Would you be able to provide a short example. I really appreciate it.

jpn
25th January 2008, 14:04
QVBoxLayout* frameLayout = new QVBoxLayout(hDivider);
frameLayout->addWidget(...);
frameLayout->addWidget(...);

tommy
26th January 2008, 00:20
This compiles fine but program crashes before it gets to graphics


MyWidget::MyWidget(QWidget* parent): QWidget(parent)
{
......
QLabel *box1 = new QLabel;
box1->setFrameStyle(QFrame::Box | QFrame::Sunken); box1->setLineWidth(2);

mainLayout = new QVBoxLayout(box1);//mainLayout is declared in my *.h file
mainLayout->addLayout(otherLayout);
......
}

What could be the problem?
Is QLabel the reason? Using "QFrame *box1 = new QFrame;" will crash the program too.

jpn
26th January 2008, 17:18
Could "otherLayout" be an uninitialized pointer? I'd suggest using a debugger and seeing backtrace/callstack to get an idea which line is causing the crash.