Results 1 to 7 of 7

Thread: dec int to HEX

  1. #1
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question dec int to HEX

    Hi ...
    I have implemented a model through which I display using the view some numbers...
    I would need something that could enable me to switch from the decimal view of them to the hex view...the problem is that I have implemented also sortfilterproxy model so I would need when the hex view is enabled to make filter model filtrate by the hex numbers and when decimal view then by decimal numbers...
    Is it possible to do something like that ?
    THX

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dec int to HEX

    Yes, you can add a flag in your model which tells it what to return to the view: decimal or hex.

    You can set that flag in higher levels(from the view or main class of your app) by casting the model() returned by the view to the appropriate class.

  3. #3
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dec int to HEX

    Quote Originally Posted by marcel View Post
    Yes, you can add a flag in your model which tells it what to return to the view: decimal or hex.
    Well this I understood...

    Quote Originally Posted by marcel View Post
    You can set that flag in higher levels(from the view or main class of your app) by casting the model() returned by the view to the appropriate class.
    This I did not at all ...what did you mean by casting the model ?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dec int to HEX

    I have implemented a model through which I display using the view some numbers...
    This means you subclassed QAbstractItemModel(or one of its subclasses).
    QAbstractItemView::model() returns a QAbstractItemModel.
    Therefore, if your model is called MyCustomModel, in order to access specific methods of this type, you must cast the QAbstractItemModel returned by model() to MyCustomModel.
    For example, you can do this in the view:
    Qt Code:
    1. MyCustomModel * myModel = dynamic_cast<MyCustomModel*>(model());
    2. if(myModel)
    3. {
    4. myModel->setMode(decOrHex); //switch to one of the two display modes
    5. }
    6. ...
    To copy to clipboard, switch view to plain text mode 
    Last edited by marcel; 31st December 2007 at 13:09. Reason: corrected sample code

  5. #5
    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: dec int to HEX

    Quote Originally Posted by marcel View Post
    Qt Code:
    1. MyCustomModel * myModel = dynamic_cast<MyCustomModel*>(model());
    2. if (myModel)
    3. myModel->setMode(MyCustomModel::DecimalDisplay); //switch to decimal
    4. else
    5. myModel->setMode(MyCustomModel::HexDisplay); //switch to hex
    6. ...
    To copy to clipboard, switch view to plain text mode 
    Oops, Marcel. There's a nasty little bug.
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    gyre (1st January 2008)

  7. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dec int to HEX

    Quote Originally Posted by jpn View Post
    Oops, Marcel. There's a nasty little bug.
    Happy New Year!

  8. #7
    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: dec int to HEX

    Quote Originally Posted by marcel View Post
    Happy New Year!
    You too, buddy. And of course, everyone else on this forum! Cheers!
    J-P Nurmi

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.