Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4241892
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:22:10+00:00 2026-05-21T03:22:10+00:00

I need to show some treeview item text striked out text into a QT

  • 0

I need to show some treeview item text striked out text into a QT treeview from Ruby.
After some reading on QT documentation and much coding, I found that only when rendering font in bold, also the strikeout was rendered.

Resulting treeview rendering.

So I wonder, where I’m doing wrong?
This is the code to achive the result shown above. Note as I set strikeout for every even row item.
I’m using Ruby 1.8.7 and Qt 4.6.2 and qt4ruby 4.4.3-6 on Mandriva Linux.

require 'Qt4'
require 'date'

class MyStandardItem < Qt::StandardItem     
  def initialize(str = nil)
    super str
  end

  def data(role = Qt::UserRole + 1)
    return super(role) unless role == Qt::FontRole
    ret_val = Qt::Font.new()
    #parameters for "fromString":font family, pointSizeF, pixelSize, QFont::StyleHint, QFont::Weight, QFont::Style, underline, strikeOut, fixedPitch, rawMode
    ret_val.fromString "sans serif,-1,-1,0,0,0,0,0,0,0"
    case role
    when Qt::FontRole
      ret_val.setStrikeOut(true) if (index.row % 2) == 0
      if index.column == 1
    ret_val.weight = Qt::Font.Bold
      else
    ret_val.weight = Qt::Font.Normal
      end
      return Qt::Variant.fromValue(ret_val)
    end
    return ret_val
  end  
end

Qt::Application.new(ARGV) do
  treeview = Qt::TreeView.new do
    model = Qt::StandardItemModel.new self
    head = [MyStandardItem.new "Qt v. #{Qt.version}"]
    head << MyStandardItem.new("Ruby v. #{VERSION}")
    head << MyStandardItem.new("Qt4Ruby v. 4.4.3-6 (Mandriva)")
    model.append_row head
    (1..10).each do |i|
      col0 = MyStandardItem.new 'some text'
      col0.check_state = ((i % 3) == 0)? Qt.Checked : Qt.Unchecked
      col0.checkable = true
      col0.editable= false
      col1 = MyStandardItem.new "line ##{i}"
      col2 = MyStandardItem.new((Date.today + i).strftime '%d/%m/%y')
      model.append_row [col0, col1, col2]
    end
    self.model = model
    show
  end
  exec
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:22:11+00:00Added an answer on May 21, 2026 at 3:22 am

    Eventually I find an hackish trick to overcome this problem. Playing around after reading again the enum QFont::Weight description I tried to set

    ret_val.weight = 51 # Qt::Font.Normal value is 50
    

    instead of

    ret_val.weight = Qt::Font.Normal
    

    and magically the normal text appears striked out!

    Maybe this strange behaviour is due to a bug on QT?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, i need to show some english and arabic text in a
In my application I need show some info popup. This is just a text
I need to show some data in a textview coming from coredata (like this
I need to show some text when a user clicks a link, and then
I need to show some text notification on statusbar of jailbreaked iphone , while
I need to show some information in a graph, the data is held in
In my app I have need to trigger show some custom view when status
I need to make a WebView show some web pages where some parts are
I've been googling this for long time! I need to show images on some
I need to create a slide show of some images that can go full

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.