Results 1 to 20 of 20

Thread: table in QLabel

  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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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
    Join Date
    Jan 2006
    Location
    Poland/Poznań
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: table in QLabel

    Quote Originally Posted by Everall
    So here is my dirty trick :
    label->resize(1,1);//resize it to 1 by 1 pixel, which QT won't allow.
    It resize this QLabel ALWAYS to minimal size, so the table is without margins, but Qt doesn't show the whole table...
    Qt Code:
    1. QLabel *label = new QLabel(0);
    2. label->resize(1,1);
    3. label->setFrameStyle(QFrame::Plain);
    4. label->setBackgroundMode(Qt::FixedColor);
    5. label->setPaletteBackgroundColor(QColor("red"));
    6. 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>");
    7. label->show();
    To copy to clipboard, switch view to plain text mode 
    gives:

    How does it look on Qt4?

    I've seen in some sources this trick with resize(1,1), but I don't remember exacly where it was... I'll look for it.
    Last edited by Pan Wojtas; 6th February 2006 at 15:34.

  14. #14
    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

    How does it look on Qt4?
    it looks like :

    Cheers
    Attached Images Attached Images

  15. #15
    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

  16. #16
    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

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

    Default Re: table in QLabel

    Quote Originally Posted by piotrpsz
    QLabel is a QWidget.
    Every QWidget have a layout (QWidget have a function member QLayout* layout()).
    Maybe is not used, but have layout.
    Eeem.... no.

    Qt Code:
    1. #include <qwidget.h>
    2. #include <qlayout.h>
    3. #include <qapplication.h>
    4.  
    5. int main(int argc, char **argv){
    6. QApplication app(argc, argv);
    7. QWidget *w = new QWidget();
    8. w->layout()->setMargin(5);
    9. delete w;
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

    On my system it crashes on "w->layout()->setMargin()" call, meaning there is no layout in the widget. A class may have methods to get or set a layout, but it doesn't mean it uses them. If you take a look at QWidget sources, you'll notice, that it only references "layout" while dealing with "height for width".

  18. #18
    piotrpsz Guest

    Default Re: table in QLabel

    Quote Originally Posted by wysota
    Eeem.... no.

    Qt Code:
    1. #include <qwidget.h>
    2. #include <qlayout.h>
    3. #include <qapplication.h>
    4.  
    5. int main(int argc, char **argv){
    6. QApplication app(argc, argv);
    7. QWidget *w = new QWidget();
    8. w->layout()->setMargin(5);
    9. delete w;
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

    On my system it crashes on "w->layout()->setMargin()" call, meaning there is no layout in the widget. A class may have methods to get or set a layout, but it doesn't mean it uses them. If you take a look at QWidget sources, you'll notice, that it only references "layout" while dealing with "height for width".
    OK
    Sorry, I should tell, that every widget CAN have a layout.
    Look a previous my post.

    Best regards
    Piotr

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

    Default Re: table in QLabel

    So set a layout for QWidget and try to do anything meaningfull with it...

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

    Default Re: table in QLabel

    I've noticed, that this extra margin on the bottom is always equal
    to "fontMetrics().height()", so it seems that Qt adds one empty line below
    each table...

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.