Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: How to show QLabels

  1. #1
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to show QLabels

    Hello everybody.

    There is a problem with showing QLabels.

    There is a QPlugin made as dll. It has an array:
    Qt Code:
    1. typedef boost::shared_ptr< QLabel > TLabel;
    2. typedef std::vector< TLabel > TLabels;
    3. typedef TLabels::iterator TLabelsIter;
    4. typedef TLabels::const_iterator TLabelsIterConst;
    To copy to clipboard, switch view to plain text mode 

    and so in the plugin's class:
    Qt Code:
    1. TLabels labels;
    To copy to clipboard, switch view to plain text mode 

    During the work of the plugin, next initialization present:
    Qt Code:
    1. TLabel newLabel;
    2. newLabel.reset(new QLabel);
    3. QFont newFont("Serif", 12);
    4. newLabel->setFont(newFont);
    5. QPalette pal( "#FFFF00");
    6. newLabel->setPalette(pal);
    7. newLabel->move(10, 10);
    8.  
    9. labels.push_back(pLabel);
    To copy to clipboard, switch view to plain text mode 

    The there is a code which simply changes text in the label:
    Qt Code:
    1. labels[j]->setText(dataQStr);
    To copy to clipboard, switch view to plain text mode 

    The plugin's class has QWidget inheritance.

    When the program starts, no labels are seen.

    If I add to the plugin's class an element:
    Qt Code:
    1. private:
    2. QMainWindow mainWindow;
    To copy to clipboard, switch view to plain text mode 

    And initialize it after with:

    Qt Code:
    1. mainWindow.show();
    To copy to clipboard, switch view to plain text mode 

    When the program starts, there is a window with NULL information in it.

    What do I need to do, in order to show the labels I have in the mainWindow?
    or is there any ways to do it without the mainWindow element?

    Thanks a lot in advance.

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

    Default Re: How to show QLabels

    How do you add the labels to the window?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    I don't really.

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    so you have to show your labels. You can do it by calling show() on them, but it is not a proper way. First of all adding the window as parent for label should show them within the window. But it is prefered to use a layout to add and position the labels within the window.

    P.S. And you can use Qt containers such a QList and there is also very nice Qt keyword such as foreach.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

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

    Default Re: How to show QLabels

    Quote Originally Posted by Pavel Abrosimov View Post
    I don't really.
    You have to add them to the layout of the central widget of the main window.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    It is really needed to use the system of coordinates for the labels (x and y from the top left corner). There is such a function in QLabels (move(int x, int y)). How would it be possible to use with the layout (I know about QHBoxLayout, but I am not sure about movement inside it)

    Thanks a lot for all the answers.

    P.S.

    About QList.
    Isn't it just an another kind of arrays? I am asking that, because it seams to be needed to add all the labels to the mainWindow (to make them children of the mainWindow), if I understood it correct. If not, how that would iteract with the mainWindow (how would mainWindow be aware about created qlist)?
    Last edited by Pavel Abrosimov; 2nd July 2009 at 21:38.

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

    Default Re: How to show QLabels

    Hmm... all what you write above makes me think you are trying to use the labels in a wrong way. Could you explain what is that you are trying to achieve?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    I need to show some information above the video. The window needs to be full screen and transparent. The last two options are seems to be achievable.

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

    Default Re: How to show QLabels

    Maybe you should use QGraphicsView instead of going through hell with labels? An alternative is to provide an overlay over the video (although I'm not sure this is possible if you're planning to use Phonon) and use QPainter to do the drawing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    To be honest, work needs to be done with QGraphicsView is unknown. We are not going to use phonon. Is there easy way to attach those labels to that mainWindow and have an ability to call move(int x, int y) on them?

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

    Default Re: How to show QLabels

    Just don't put them into layouts although it'd really be simpler with the graphics view. And if you're going to show the video full screen, you'll probably want to use QWidget instead of QMainWindow.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    The class, from which qtplugin is made of is already a QWidget. I need some window. I just didn't know how else can I do it, apart from calling QMainWindow.

  13. #13
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    Even QWidget can be used to hold labels and be shown as a window.
    Something like -
    Qt Code:
    1. main()
    2. {
    3. ....
    4. // get labels from your plugin.
    5. QWidget window;
    6. // add ur labels to window. The position u set is relative to window.
    7. window.show();
    8. ....
    9. }
    To copy to clipboard, switch view to plain text mode 

  14. #14
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    aamer4yu Thanks for information.

    So if I would call on them during initialization:
    Qt Code:
    1. TLabel label(new QLabel(this));
    2. label->move(x, y);
    3. labels.bush_back(label);
    4. ...
    5. show();
    To copy to clipboard, switch view to plain text mode 


    and all the labels would be pointers:
    Qt Code:
    1. typedef QLabel* TLabel;
    To copy to clipboard, switch view to plain text mode 

    There is a white window with nothing in it. Am I missing something?
    A call label->show(); doesn't change anything.
    Last edited by Pavel Abrosimov; 3rd July 2009 at 10:03.

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

    Default Re: How to show QLabels

    Can you prepare a minimal compilable example that does what your code does so that we can work on it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    header:
    Qt Code:
    1. typedef QLabel* TLabel;
    2. typedef std::vector< TLabel > TLabels;
    3. typedef TLabels::iterator TLabelsIter;
    4. typedef TLabels::const_iterator TLabelsIterConst;
    5.  
    6. class MYclass:
    7. public QWidget,
    8. {
    9. Q_OBJECT
    10. Q_INTERFACES(NTlParser::IBase NTlParser::ICfg NTlParser::IDataConsumer)
    11.  
    12. public:
    13. MYclass(QWidget *parent = 0);
    14. ~MYclass();
    15. void doSmth();
    16. private:
    17. void AssertLabels();
    18. TLabels labels;
    19.  
    20. };
    To copy to clipboard, switch view to plain text mode 

    in source:
    Qt Code:
    1. MYclass::MYclass(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. }
    5. MYclass::~MYclass()
    6. {
    7. }
    8.  
    9. void MYclass::AssertLabels()
    10. {
    11. for(uint i = 0; i < 4; ++i){
    12. TLabel pLabel(new QLabel(this));
    13. QFont newFont("Serif", 12);
    14. pLabel->setFont(newFont);
    15. QPalette pal("#FFFF00");
    16. pLabel->setPalette(pal);
    17. pLabel->move(10, 10 + i * 20);
    18. pLabel->setText("Fake text");
    19.  
    20. labels.push_back(pLabel);
    21. }
    22. show();//need to show them, right?
    23. }
    24.  
    25. void MYclass::doSmth()
    26. {
    27. for(uint i = 0; i < labels.size(); ++i){
    28. labels[i]->setText("New Fake text");
    29. }
    30. }
    To copy to clipboard, switch view to plain text mode 

    Something like that

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

    Default Re: How to show QLabels

    I meant something I could compile and run, not "something like that"

    Anyway, do you call AssertLabels() anywhere? And what's the purpose of using that TLabel?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #18
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    sorry, forgot to add:

    Qt Code:
    1. MYclass::MYclass(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. AssertLabels();
    5. }
    To copy to clipboard, switch view to plain text mode 

    Unfortunately, there is nothing I could give and it would compile straight away

    But the code I posted is very close to what I need to achieve (some methods of parameters and quantities are different)

    Thanks a lot for your help

  19. #19
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show QLabels

    Ok. The problem is solved by doing next:
    Add the paintEvent(QPaintEvent *) and its description in source file:

    void MYclass:aintEvent(QPaintEvent *)
    {
    QPainter painter(this);
    }

    Thanks everyone for help.

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

    Default Re: How to show QLabels

    Quote Originally Posted by Pavel Abrosimov View Post
    Ok. The problem is solved by doing next:
    Add the paintEvent(QPaintEvent *) and its description in source file:

    void MYclass:aintEvent(QPaintEvent *)
    {
    QPainter painter(this);
    }
    Hmm.... you really shouldn't do that... If you need something like this then it means you were not deriving from QWidget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. problem with show Chinese
    By osmanthus in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2009, 02:49
  2. How to show two main windows?
    By Althor in forum Newbie
    Replies: 4
    Last Post: 13th October 2008, 08:30
  3. Show dialog in screen center
    By mourad in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2008, 13:41
  4. Rezizing the Qlabels vertically
    By anju123 in forum Qt Programming
    Replies: 3
    Last Post: 3rd January 2008, 15:35
  5. WYSIWYG html, Window show png icon mac no!
    By patrik08 in forum Qt Programming
    Replies: 10
    Last Post: 25th May 2006, 12:01

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.