Skip to content

Instantly share code, notes, and snippets.

@wedesoft
Created July 27, 2012 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wedesoft/3188232 to your computer and use it in GitHub Desktop.
Save wedesoft/3188232 to your computer and use it in GitHub Desktop.
Qt4 Clipboard
#!/usr/bin/env ruby
require 'rubygems'
require 'Qt4'
class Test < Qt::Widget
def keyPressEvent(e)
if e.modifiers == Qt::ControlModifier
mimeData = $qApp.clipboard.mimeData
case e.key
when Qt::Key_C
puts 'copy!'
when Qt::Key_V
puts 'paste!'
p mimeData.formats
if mimeData.formats.member? 'text/uri-list'
p mimeData.text
p mimeData.urls.collect { |url| url.toLocalFile }
#mimeData.urls.each do |url|
# File.open url.toLocalFile, 'rb' do |f|
# f.read
# end
#end
end
end
end
end
end
app = Qt::Application.new ARGV
window = Test.new
window.show
window.raise
app.exec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment