Results 1 to 7 of 7

Thread: Problems with layout

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problems with layout

    Hi I would layout some widget inside my class derived from QFrame.
    This is the interface:

    Qt Code:
    1. class PanelInfo : public QFrame
    2. {
    3. Q_OBJECT
    4. public:
    5. PanelInfo(QWidget* parent);
    6. ~PanelInfo();
    7.  
    8. public slots:
    9. void panValueChanged(int);
    10. void volValueChanged(int);
    11.  
    12. protected:
    13. private:
    14. QLabel* m_durationLabel;
    15. QLabel* m_channelsLabel;
    16. QLabel* m_freqLabel;
    17. QLabel* m_bitsLabel;
    18.  
    19. QSlider* m_panSlider;
    20. QSlider* m_volSlider;
    21.  
    22. QDoubleSpinBox* m_freqControl;
    23. };
    To copy to clipboard, switch view to plain text mode 

    In the ctor I would layout the widget but the result is not the expected:
    Qt Code:
    1. PanelInfo::PanelInfo(QWidget* parent /* = 0 */ )
    2. : QFrame(parent)
    3. {
    4. setFrameStyle( QFrame::Box | QFrame::Raised );
    5.  
    6. setMinimumSize( QSize(120, 240) );
    7. setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
    8.  
    9. /* labels */
    10. m_durationLabel = new QLabel("DURATION");
    11. m_channelsLabel = new QLabel("CHANNELS");
    12. m_freqLabel = new QLabel("FREQ");
    13. m_bitsLabel = new QLabel("BITS");
    14.  
    15. QVBoxLayout* ll = new QVBoxLayout();
    16. ll->setContentsMargins(0, 0, 0, 0);
    17. ll->setSpacing(0); //<---doesn't work in my case
    18. ll->addWidget( m_durationLabel );
    19. ll->addWidget( m_channelsLabel );
    20. ll->addWidget( m_freqLabel );
    21. ll->addWidget( m_bitsLabel );
    22.  
    23. m_panSlider = new QSlider(Qt::Horizontal);
    24. m_panSlider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    25. m_panSlider->setMinimum( -100 );
    26. m_panSlider->setMaximum( +100 );
    27. m_panSlider->setValue( 0 );
    28.  
    29. m_volSlider = new QSlider(Qt::Horizontal);
    30. m_volSlider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    31. m_volSlider->setMinimum( 0 );
    32. m_volSlider->setMaximum( +100 );
    33. m_volSlider->setValue( 100 );
    34.  
    35. /* spinbox */
    36. m_freqControl = new QDoubleSpinBox();
    37. m_freqControl->setMinimum( 0.0 );
    38. m_freqControl->setMaximum( 3.0 );
    39. m_freqControl->setValue( 1.0 );
    40. m_freqControl->setSingleStep( 0.1 );
    41. m_freqControl->setWrapping(1);
    42.  
    43. QVBoxLayout* vl = new QVBoxLayout();
    44. vl->addLayout(ll);
    45.  
    46. vl->addWidget(m_panSlider);
    47. vl->addWidget(m_volSlider);
    48.  
    49. vl->addWidget(m_freqControl);
    50. setLayout(vl);
    51.  
    52. connect(m_panSlider, SIGNAL( valueChanged(int) ), this, SLOT( panValueChanged(int) ) );
    53. connect(m_volSlider, SIGNAL( valueChanged(int) ), this, SLOT( volValueChanged(int) ) );
    54. connect(m_freqControl, SIGNAL( valueChanged(double) ),this, SLOT( freqChanged( double ) ) );
    55. }
    To copy to clipboard, switch view to plain text mode 

    The result is that I have some not desired spaces between the labels also setting setSpacing to 0px. Layout are not completely clear to me.
    In the attached image I drawn some red lines indicating the spaces I would delete.

    Best
    Attached Images Attached Images
    Franco Amato

Similar Threads

  1. QWidget layout problems
    By MarkoSan in forum Newbie
    Replies: 3
    Last Post: 12th January 2010, 10:23
  2. Problems with QMainWindow and layout
    By franco.amato in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2009, 22:49
  3. Replies: 0
    Last Post: 25th May 2009, 10:00
  4. Replies: 7
    Last Post: 15th June 2007, 16:13
  5. Resizing problems when applying a layout
    By JimBrown in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 22:54

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
  •  
Qt is a trademark of The Qt Company.