Results 1 to 8 of 8

Thread: drawing an unfixed line?

  1. #1
    Join Date
    Nov 2007
    Posts
    103
    Thanks
    71
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default drawing an unfixed line?

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: drawing an unfixed line?

    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    tommy (23rd January 2008)

  4. #3
    Join Date
    Nov 2007
    Posts
    103
    Thanks
    71
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: drawing an unfixed line?

    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.

    Qt Code:
    1. QLabel *hDivider1 = new QLabel;
    2. hDivider1->setFrameStyle(QFrame::Box | QFrame::Sunken);
    3. hDivider1->setLineWidth(2);
    4.  
    5. clusterLayout->addWidget(hDivider1);
    To copy to clipboard, switch view to plain text mode 
    Last edited by tommy; 23rd January 2008 at 23:17.

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: drawing an unfixed line?

    Install a layout on the frame and add widgets to it.
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    tommy (25th January 2008)

  7. #5
    Join Date
    Nov 2007
    Posts
    103
    Thanks
    71
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: drawing an unfixed line?

    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.

  8. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: drawing an unfixed line?

    Qt Code:
    1. QVBoxLayout* frameLayout = new QVBoxLayout(hDivider);
    2. frameLayout->addWidget(...);
    3. frameLayout->addWidget(...);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  9. The following user says thank you to jpn for this useful post:

    tommy (26th January 2008)

  10. #7
    Join Date
    Nov 2007
    Posts
    103
    Thanks
    71
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: drawing an unfixed line?

    This compiles fine but program crashes before it gets to graphics
    Qt Code:
    1. MyWidget::MyWidget(QWidget* parent): QWidget(parent)
    2. {
    3. ......
    4. QLabel *box1 = new QLabel;
    5. box1->setFrameStyle(QFrame::Box | QFrame::Sunken); box1->setLineWidth(2);
    6.  
    7. mainLayout = new QVBoxLayout(box1);//mainLayout is declared in my *.h file
    8. mainLayout->addLayout(otherLayout);
    9. ......
    10. }
    To copy to clipboard, switch view to plain text mode 
    What could be the problem?
    Is QLabel the reason? Using "QFrame *box1 = new QFrame;" will crash the program too.

  11. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: drawing an unfixed line?

    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.
    J-P Nurmi

  12. The following user says thank you to jpn for this useful post:

    tommy (26th January 2008)

Similar Threads

  1. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48
  2. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  3. Access Violation on Signal Emit
    By khagzan in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2007, 22:51
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.