Results 1 to 20 of 20

Thread: table in QLabel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Poland/Poznań
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default table in QLabel

    Qt Code:
    1. QLabel *label = new QLabel(0);
    2. label->setFrameStyle(QFrame::Plain);
    3. label->setBackgroundMode(Qt::FixedColor);
    4. label->setPaletteBackgroundColor(QColor("red"));
    5. label->setText("<table bgcolor=white border=0 cellspacing=0 cellpadding=0><tr><td>aaa<br>ccc<br>ddd</td><td>bbb</td></tr></table>");
    6. label->show();
    To copy to clipboard, switch view to plain text mode 
    and effect:


    What can I do to avoid this red border above, under and on the right of the table?
    I'd like to have a QLabel that consist ONLY the table - and nothing else (no margins).

    (I've made red and white colors only to show you this margins)
    Last edited by Pan Wojtas; 5th February 2006 at 13:20.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: table in QLabel

    Did you try:
    Qt Code:
    1. label->setScaledContents( true );
    To copy to clipboard, switch view to plain text mode 
    and/or
    Qt Code:
    1. label->setAlignment( Qt::AlignCenter );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Poland/Poznań
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: table in QLabel

    setScaledContents doesn't change anything;
    setAlignment only moves this table to the center of QLabel (makes another margin on the left side).

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: table in QLabel

    Then try:
    Qt Code:
    1. label->setText("<table width=\"100%\" bgcolor=white border=0 cellspacing=0 cellpadding=0><tr><td>aaa<br>ccc<br>ddd</td><td>bbb</td></tr></table>");
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Poland/Poznań
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: table in QLabel

    It looks like this:


    So it removes left and right margins, but QLabel is a way too wide.
    For me more serious issue are margins above and below table. "height=100%" doesn't work.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: table in QLabel

    Quote Originally Posted by Pan Wojtas
    For me more serious issue are margins above and below table. "height=100%" doesn't work.
    Then make the QLabel smaller --- there isn't enough content to fill it.

  7. #7
    Join Date
    Jan 2006
    Location
    Poland/Poznań
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: table in QLabel

    Quote Originally Posted by jacek
    Then make the QLabel smaller --- there isn't enough content to fill it.
    I don't understand...
    I've made larger QLabel:

    but there is still the same margin

    I've noticed, that it is always 16px at the bottom and 2px at the top...

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: table in QLabel

    Maybe you should just find some other way to place your table?

  9. #9
    piotrpsz Guest

    Default Re: table in QLabel

    Can you try:

    label->layout()->setSpacing( ... ),
    label->layout()->setMargin( ... ),


  10. #10
    Join Date
    Jan 2006
    Location
    Poland/Poznań
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: table in QLabel

    Quote Originally Posted by piotrpsz
    label->layout()->setSpacing( ... ),
    label->layout()->setMargin( ... ),
    But it makes "segmentation fault"...

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: table in QLabel

    QLabel is not a container, thus it doesn't have a layout (unless you provide one, but I don't know what will happen then... QLabel is not supposed to have a layout).

  12. #12
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: table in QLabel

    What can I do to avoid this red border above, below
    i did some testing on QT4. I know you're on QT3, but i wanted to see the behaviour here also.

    QT4 doesn't provide the left and right margins, but you get top and bottom margins. So this is better than QT3.

    But the margins on top and bottom arestill there.
    I noticed I could drag the dialogbox to a minimum size = sizehint of the textlabel. I couldn't drag it smaller. (because of QT's wonderfull sizehint functionality)

    So here is my dirty trick :
    label->resize(1,1);//resize it to 1 by 1 pixel, which QT won't allow.

    and in QT4 the dialogbox is the size you want without the margins.

    I hope it will work for QT3 also.

    Cheers

  13. #13
    piotrpsz Guest

    Default Re: table in QLabel

    Quote Originally Posted by wysota
    QLabel is not a container, thus it doesn't have a layout (unless you provide one, but I don't know what will happen then... QLabel is not supposed to have a layout).
    QLabel is a QWidget.
    Every QWidget have a layout (QWidget have a function member QLayout* layout()).
    Maybe is not used, but have layout.

    Piotr

  14. #14
    piotrpsz Guest

    Default Re: table in QLabel

    Quote Originally Posted by Pan Wojtas
    But it makes "segmentation fault"...
    That's right.
    For label function layout() returns 0 (NULL).

    But try this code:

    Qt Code:
    1. QLabel* lbl = new QLabel( "cos_niecos", this );
    2. QHBoxLayout* lbl_layout = new QHBoxLayout( lbl );
    3. QLayout* lay = lbl->layout();
    4.  
    5. if( 0 == lay ) qWarning( "lay is 0" );
    6. else qWarning( "OK" );
    7.  
    8. lbl->layout()->setMargin( 0 );
    9. lbl->layout()->setSpacing( 0 );
    To copy to clipboard, switch view to plain text mode 

    This code functioning.
    Piotr

Similar Threads

  1. Trouble with QLabel
    By dany_MB in forum Newbie
    Replies: 3
    Last Post: 14th August 2009, 08:21
  2. Postgresql QSqlRelationalTableModel empty table
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2008, 17:18
  3. Replies: 3
    Last Post: 5th October 2008, 23:41
  4. Replies: 3
    Last Post: 17th July 2008, 07:43
  5. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50

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.