Results 1 to 2 of 2

Thread: absolutely center text alignment in qtablewidgetitem that has an icon

  1. #1
    Join Date
    Nov 2009

    Default absolutely center text alignment in qtablewidgetitem that has an icon

    I have a QTableWidget which contains cells which may or may not contain QIcons in them. When I align the texts of cells with icons in them, they are centered more right than cells without icons in them.

    offset icon text alignment.jpg

    How do I make the text in cells with icons center so that they align with the entire cell, and not the text portion of the QTableWidgetItem?

    I tried:

    Qt Code:
    1. QTableWidgetItem::setTextAlignment(Qt::AlignAbsolute | Qt:: AlignCenter)
    To copy to clipboard, switch view to plain text mode 

    I have read into similar threads describing the use of QItemDelegates when considering icon alignment, but does this method work for QTableWidgetItems via medelling with the Qt:isplayRole portion of QItemDelegate or am I completely off?
    Last edited by positive_4_life; 4th April 2011 at 20:14.

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: absolutely center text alignment in qtablewidgetitem that has an icon

    Yes, you need a custom delegate. Compute the positions yourself and render the items (semi-)manually.
    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. Replies: 1
    Last Post: 21st November 2009, 21:38
  2. Icon Alignment
    By wirasto in forum Newbie
    Replies: 2
    Last Post: 18th October 2009, 18:49
  3. qstandarditem how sisplay icon in center?
    By yunpeng880 in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2009, 10:14
  4. Centering An Icon In A QTableWidgetItem?
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 15th November 2007, 00:11
  5. Icon Text Alignment
    By nupul in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 05:47

Tags for this Thread


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.