Results 1 to 5 of 5

Thread: QLabel text not selectble even when i set Qt::TextSelectableByMouse inside QStyledIte

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    83

    Default Re: QLabel text not selectble even when i set Qt::TextSelectableByMouse inside QStyle

    Thanks for all , i know i did wrong with the QLabel but
    im trying to make text that is selectable , it doesn't have to be Label , i before that used to drow simple text but didn't found any way to make it selectable
    like this:
    Qt Code:
    1. painter->save();
    2. painter->setFont(smallerBoldFont);
    3. if (!isSelected && !isActive)
    4. painter->setPen(QPen(option.palette.brush(QPalette::Mid), 0));
    5. QString authorString = pStreamItem->author();
    6. QSizeF authorStringSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, authorString ) );
    7. textLoc.setX(textLoc.x() + publishedStringSize.width() + PADDING);
    8. QRectF authorTextBox( textLoc , authorStringSize);
    9. painter->drawText(authorTextBox, Qt::AlignLeft | Qt::AlignTop, authorString);
    10. painter->restore();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: QLabel text not selectble even when i set Qt::TextSelectableByMouse inside QStyle

    Why you're using painter in the first place?
    Don't.

    Use QLineEdit and set it to read only but don't paint it anywhere, leave it to Qt!
    Just parent it to widget you want it appear in.
    You can manipulate background palette to make it blend with the parent widget if you want.

Similar Threads

  1. Replies: 3
    Last Post: 19th October 2011, 12:41
  2. Replies: 1
    Last Post: 23rd January 2010, 13:16
  3. Set Text inside group box
    By bismitapadhy in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2009, 08:26
  4. text inside QGraphicsEllipseItem
    By stoned in forum Qt Programming
    Replies: 3
    Last Post: 10th June 2008, 07:44
  5. rotate Qlabel inside a QPopupMenu
    By mickey in forum Newbie
    Replies: 7
    Last Post: 1st May 2006, 17:33

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.