Results 1 to 5 of 5

Thread: Question about align

  1. #1
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Question about align

    I tried to do a simple thing:

    Qt Code:
    1. painter->drawText(rect, Qt::AlignTop && Qt::AlignRight, str);
    2. painter->drawLine(rect.topLeft(), rect.bottomRight());
    3. painter->drawText(rect, Qt::AlignBottom, "ASD");
    To copy to clipboard, switch view to plain text mode 

    But it didn't work...
    The top line get's aligned only top, but not top + right.
    How can i get it to align top + right?
    I think it has something to do with flags, but i could not confirm that idea.

  2. #2
    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: Question about align

    You are using a wrong bitwise operation. Firstly && is not a bitwise operation so Qt::AlignTop && Qt::AlignRight returns "true" (or "1") is neigher of the two components are "0". Secondly "&&" is a conjunction operator and not alternative which is what you need.
    Qt Code:
    1. painter->drawText(rect, Qt::AlignTop|Qt::AlignRight, str);
    To copy to clipboard, switch view to plain text mode 
    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. The following user says thank you to wysota for this useful post:

    Archa4 (14th March 2011)

  4. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Question about align

    Qt Code:
    1. painter->drawText(rect, Qt::AlignTop | Qt::AlignRight, str);
    To copy to clipboard, switch view to plain text mode 
    More info: C bitwise operators
    -------
    looks like I'm too slow
    Last edited by stampede; 14th March 2011 at 08:18. Reason: wysota was faster

  5. #4
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about align

    Thanks it worked
    I also tried "Qt::AlignTop + Qt::AlignRight" and it worked to.

  6. #5
    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: Question about align

    Quote Originally Posted by Archa4 View Post
    I also tried "Qt::AlignTop + Qt::AlignRight" and it worked to.
    In this particular situation yes but in general this is not correct. Consider this:
    Qt Code:
    1. Qt::AlignTop+Qt::AlignTop
    To copy to clipboard, switch view to plain text mode 
    Logically this should be Qt::AlignTop but it won't be, Thus you should use "|".
    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.


  7. The following user says thank you to wysota for this useful post:

    Archa4 (14th March 2011)

Similar Threads

  1. QTabWidget align
    By AlexD in forum Qt Programming
    Replies: 6
    Last Post: 10th August 2012, 13:19
  2. QTextEdit align right.
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 7th November 2009, 20:43
  3. QItemDelegate Align
    By aekilic in forum Qt Programming
    Replies: 43
    Last Post: 1st April 2009, 07:52
  4. QTableView and problems with align
    By mamyte03@gmail.com in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 07:10
  5. QTextTableCell vertical align
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 10th July 2007, 09: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.