Results 1 to 11 of 11

Thread: QGraphicsTextItem in a Widget ,Is it Possible ??

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsTextItem in a Widget ,Is it Possible ??

    Hi,
    I have written this code in my class derived from QWidget,but it shows no text ..!!

    Qt Code:
    1. class ProgressWidget:public QWidget
    2. {
    3. ..
    4. ..
    5. };
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void ProgressWidget::instructionStringOne()
    2. {
    3. txt1->setPlainText(str1);
    4. txt1->setFont(fontStr1);
    5. txt1->setTextWidth(TEXT_WIDTH);
    6. txt1->setPos(INSTRUCTION_TEXT_1_X,INSTRUCTION_TEXT_1_Y);
    7. txt1->show();
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    should it work ot this is a mistake....i have also tried different values in setPos but it shows no text..

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsTextItem in a Widget ,Is it Possible ??

    You can use QGraphicsItems (and subclasses) only in a QGraphicsView (or -Scene for that matter).

    Just use a QLabel.

  3. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsTextItem in a Widget ,Is it Possible ??

    Thanks,i was also thinking the same...but wasnt sure about it..
    any ways when i used the QLabel ,i faced a problem that my text is not fully shown on the screen until and unless i introduce some spacing in the text here is the code..

    Qt Code:
    1. #define SECOND_TRAINING_COMMAND "Do as you would want to do normally.Be accurate an' 'd avoid mistakes."
    2. QLabel *txt1;
    To copy to clipboard, switch view to plain text mode 
    the spacing shown in the above string is necessary or it does not shows the whole string..
    Qt Code:
    1. str2 = SECOND_TRAINING_COMMAND;
    2. txt2 = new QLabel(this,Qt::SubWindow);
    3. txt2->setText(str2);
    4. txt2->setFont(fontStr2);
    5. txt2->setGeometry(INSTRUCTION_TEXT_2_X,INSTRUCTION_TEXT_2_Y,TEXT_WIDTH,TEXT_WIDTH);
    6. txt2->setWordWrap(TRUE);
    7. txt2->show();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsTextItem in a Widget ,Is it Possible ??

    any help ??

  5. #5
    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: QGraphicsTextItem in a Widget ,Is it Possible ??

    What does it show when u dont give the space ??

  6. #6
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsTextItem in a Widget ,Is it Possible ??

    it just shows the first part of the string i.e the part which is before spaces and and the last word of the string on the next line,..in my case which is
    Do as you would want to do normally.Be accurate an
    mistakes.

  7. #7
    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: QGraphicsTextItem in a Widget ,Is it Possible ??

    What happens if u simply use -

    Qt Code:
    1. str2 = SECOND_TRAINING_COMMAND;
    2. txt2 = new QLabel(this);
    3. this->setCentralWidget(txt2); // assuming this is QMAinWindow
    4. txt2->setText(str2);
    5.  
    6. // and from main()
    7. mainWindow->show();
    To copy to clipboard, switch view to plain text mode 

    May be somethings wrong when u are setting geometry

  8. #8
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsTextItem in a Widget ,Is it Possible ??

    this seems to be more confusing,in my case i want the text to be print on a widget ,i am not sure how it works on mainwindow

  9. #9
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsTextItem in a Widget ,Is it Possible ??

    problem solved but i didnt understand how it works..!!

    Qt Code:
    1. txt2->setGeometry(INSTRUCTION_TEXT_2_X,INSTRUCTION_TEXT_2_Y,TEXT_WIDTH,TEXT_WIDTH);
    To copy to clipboard, switch view to plain text mode 
    to clarify ,i just reduce the TEXT_WIDTH from 450 to 350 and it worked...
    any idea y ...??

  10. #10
    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: QGraphicsTextItem in a Widget ,Is it Possible ??

    How about using layouts. Your calculation for TEXT_WIDTH (350px) might happen to "work" on your screen, but just imagine if somebody else has a different font...
    J-P Nurmi

  11. #11
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsTextItem in a Widget ,Is it Possible ??

    ya ,this seems logical ,i will work on it ,thanks for pointing it out,

Similar Threads

  1. How to Open & Close a Widget ?!!
    By Fatla in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2008, 20:39
  2. Replies: 9
    Last Post: 22nd February 2008, 16:22
  3. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  4. Controlling which widget on top layer?
    By JonathanForQT4 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2007, 14:27
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

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.