c++ - Huge "Grid" of PushButtons lags awfully, buttons can't be enabled -
in project, have 256 tiny pushbuttons in 1 16x16 grid layout. (yeah took forever.) editing , running program laggy. also, strange reason, qt not let me enable of buttons, other buttons side work fine?
is there easy way determine square of grid clicked without having bunch of buttons? (like following cursor on image maybe?)
also, when each "square" of grid clicked, becomes "selection" , needs "square" selected. (think huge chess board)
here pic: http://gyazo.com/988cdbb59b3d1f1873c41bf91b1408fd
later on, need again 54x54 size grid (2916 buttons) , don't want button button.
thanks time, hope understand question :)
you can easy way, i've explained in code, if have questions feel free ask, , please, accept answer if solved problem :)
import sys pyqt4 import qtgui, qtcore pyqt4.qtgui import * pyqt4.qtcore import * class drawimage(qmainwindow): def __init__(self, parent=none): super(qmainwindow, self).__init__(parent) self.setwindowtitle('select window') #you can set grid size here ... 8x8, 16x16 , bigger numbers (54x54) sure image big enough, because qwidget can't smaller ~20 pixels self.gridsize = 16 mainwidget = qwidget() self.setcentralwidget(mainwidget) self.scene = qgraphicsscene() view = qgraphicsview(self.scene) layout = qvboxlayout() layout.addwidget(view) mainwidget.setlayout(layout) self.image = qimage('image.jpg')# put image name here, image (suppose grid) must @ same folder or put full path pixmapitem = qgraphicspixmapitem(qpixmap(self.image), none, self.scene) pixmapitem.mousepressevent = self.pixelselect def pixelselect( self, event ): #add whatever want widget,any functionality or can add image example, i've colored wdg = qwidget() layout = qvboxlayout() palette = qpalette(wdg.palette()) palette.setbrush(qpalette.background, qcolor(200,255,255)) wdg.setpalette(palette) wdg.setlayout(layout) self.scene.addwidget(wdg) #calculate size , position added widget imagesize = self.image.size() width = imagesize.width() height = imagesize.height() #size wgwidth = float(width)/self.gridsize wgheight = float(height)/self.gridsize wdg.setfixedsize(wgwidth,wgheight) #position wgxpos = int(event.pos().x()/wgwidth) * wgwidth wgypos = int(event.pos().y()/wgheight) * wgheight wdg.move(wgxpos, wgypos) #which square clicked? print "square @ row ", int(event.pos().y()/wgheight)+1,", column ",int(event.pos().x()/wgwidth)+1, "is clicked" def main(): app = qtgui.qapplication(sys.argv) form = drawimage() form.show() app.exec_() if __name__ == '__main__': main()
also, if want display simple square image on grid image, @ question/solution had: qgraphicspixmapitem won't show on other qgraphicspixmapitem
Comments
Post a Comment